sequence
stringlengths
1.25k
34.6k
code
stringlengths
75
8.58k
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'handle_django_settings'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '5', 'type': 'block', 'children': ['6', '8', '17', '28', '39', '47', '66', '83', '90', '99', '107', '130', '147', '153', '159', '165', '291', '305', '416', '425', '432', '454']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''Attempts to load a Django project and get package dependencies from\n settings.\n Tested using Django 1.4 and 1.8. Not sure if some nuances are missed in\n the other versions.\n '''"},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'old_sys_path'},{'id': '11', 'type': 'subscript', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '15', 'type': 'slice', 'children': ['16']},{'id': '16', 'type': 'colon', 'children': []},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'dirpath'},{'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': 'os'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'project'},{'id': '31', 'type': 'call', 'children': ['32', '37']},{'id': '32', 'type': 'attribute', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'dirpath'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'cwd'},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'getcwd'},{'id': '46', 'type': 'argument_list', 'children': []},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'project_path'},{'id': '50', 'type': 'call', 'children': ['51', '56']},{'id': '51', 'type': 'attribute', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'normpath'},{'id': '56', 'type': 'argument_list', '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': 'os'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'dirpath'},{'id': '65', 'type': 'string', 'children': [], 'value': "'..'"},{'id': '66', 'type': 'if_statement', 'children': ['67', '72']},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': 'not'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'project_path'},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '80']},{'id': '75', 'type': 'attribute', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82']},{'id': '81', 'type': 'integer', 'children': [], 'value': '0'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'project_path'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'chdir'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'project_path'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'project_settings'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'string', 'children': [], 'value': "'{}.settings'"},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'project'},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '106']},{'id': '101', 'type': 'subscript', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '105', 'type': 'string', 'children': [], 'value': "'DJANGO_SETTINGS_MODULE'"},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'project_settings'},{'id': '107', 'type': 'try_statement', 'children': ['108', '119']},{'id': '108', 'type': 'block', 'children': ['109', '112']},{'id': '109', 'type': 'import_statement', 'children': ['110']},{'id': '110', 'type': 'dotted_name', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'django'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'django'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'setup'},{'id': '117', 'type': 'lambda', 'children': ['118']},{'id': '118', 'type': 'False', 'children': []},{'id': '119', 'type': 'except_clause', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'ImportError'},{'id': '121', 'type': 'block', 'children': ['122', '129']},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'string', 'children': [], 'value': "'Found Django settings, but Django is not installed.'"},{'id': '129', 'type': 'return_statement', 'children': []},{'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': 'log'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'string', 'children': [], 'value': "'Loading Django Settings (Using {}): {}'"},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '140', 'type': 'argument_list', 'children': ['141', '146']},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'django'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'get_version'},{'id': '145', 'type': 'argument_list', 'children': []},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '147', 'type': 'import_from_statement', 'children': ['148', '151']},{'id': '148', 'type': 'dotted_name', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'django'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '151', 'type': 'dotted_name', 'children': ['152']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'LazySettings'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'installed_apps'},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '158', 'type': 'argument_list', 'children': []},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'settings_imports'},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '164', 'type': 'argument_list', 'children': []},{'id': '165', 'type': 'try_statement', 'children': ['166', '266']},{'id': '166', 'type': 'block', 'children': ['167', '173', '179', '213']},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '170', 'type': 'call', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'LazySettings'},{'id': '172', 'type': 'argument_list', 'children': []},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'call', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '177', 'type': 'identifier', 'children': [], 'value': '_setup'},{'id': '178', 'type': 'argument_list', 'children': []},{'id': '179', 'type': 'for_statement', 'children': ['180', '183', '193']},{'id': '180', 'type': 'pattern_list', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '183', 'type': 'call', 'children': ['184', '192']},{'id': '184', 'type': 'attribute', 'children': ['185', '191']},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'vars'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '190', 'type': 'identifier', 'children': [], 'value': '_wrapped'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '192', 'type': 'argument_list', 'children': []},{'id': '193', 'type': 'block', 'children': ['194']},{'id': '194', 'type': 'if_statement', 'children': ['195', '206']},{'id': '195', 'type': 'boolean_operator', 'children': ['196', '199'], 'value': 'and'},{'id': '196', 'type': 'comparison_operator', 'children': ['197', '198'], 'value': 'not'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '198', 'type': 'identifier', 'children': [], 'value': '_excluded_settings'},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '203', 'type': 'argument_list', 'children': ['204', '205']},{'id': '204', 'type': 'string', 'children': [], 'value': "r'^[A-Z_]+$'"},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '206', 'type': 'block', 'children': ['207']},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'call', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'scan_django_settings'},{'id': '210', 'type': 'argument_list', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'settings_imports'},{'id': '213', 'type': 'for_statement', 'children': ['214', '215', '221']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '215', 'type': 'call', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '217', 'type': 'argument_list', 'children': ['218', '219', '220']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '219', 'type': 'string', 'children': [], 'value': "'INSTALLED_APPS'"},{'id': '220', 'type': 'list', 'children': [], 'value': '[]'},{'id': '221', 'type': 'block', 'children': ['222']},{'id': '222', 'type': 'if_statement', 'children': ['223', '234', '257']},{'id': '223', 'type': 'boolean_operator', 'children': ['224', '229'], 'value': 'and'},{'id': '224', 'type': 'call', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '226', 'type': 'argument_list', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '228', 'type': 'string', 'children': [], 'value': "'__file__'"},{'id': '229', 'type': 'call', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '231', 'type': 'argument_list', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '233', 'type': 'string', 'children': [], 'value': "'__file__'"},{'id': '234', 'type': 'block', 'children': ['235', '250']},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '240']},{'id': '237', 'type': 'pattern_list', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'imp'},{'id': '239', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'import_path_from_file'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'call', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '247', 'type': 'argument_list', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '249', 'type': 'string', 'children': [], 'value': "'__file__'"},{'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': 'installed_apps'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'imp'},{'id': '257', 'type': 'else_clause', 'children': ['258']},{'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': 'installed_apps'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '264', 'type': 'argument_list', 'children': ['265']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '266', 'type': 'except_clause', 'children': ['267', '271']},{'id': '267', 'type': 'as_pattern', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '269', 'type': 'as_pattern_target', 'children': ['270']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '271', 'type': 'block', 'children': ['272', '280', '290']},{'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': 'error'},{'id': '277', 'type': 'argument_list', 'children': ['278', '279']},{'id': '278', 'type': 'string', 'children': [], 'value': "'Could not load Django settings: %s'"},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '280', 'type': 'expression_statement', 'children': ['281']},{'id': '281', 'type': 'call', 'children': ['282', '285']},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '285', 'type': 'argument_list', 'children': ['286', '287']},{'id': '286', 'type': 'string', 'children': [], 'value': "''"},{'id': '287', 'type': 'keyword_argument', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'exc_info'},{'id': '289', 'type': 'True', 'children': []},{'id': '290', 'type': 'return_statement', 'children': []},{'id': '291', 'type': 'if_statement', 'children': ['292', '297']},{'id': '292', 'type': 'boolean_operator', 'children': ['293', '295'], 'value': 'or'},{'id': '293', 'type': 'not_operator', 'children': ['294']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'installed_apps'},{'id': '295', 'type': 'not_operator', 'children': ['296']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'settings_imports'},{'id': '297', 'type': 'block', 'children': ['298']},{'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': 'log'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '303', 'type': 'argument_list', 'children': ['304']},{'id': '304', 'type': 'string', 'children': [], 'value': "'Got empty settings values from Django settings.'"},{'id': '305', 'type': 'try_statement', 'children': ['306', '398']},{'id': '306', 'type': 'block', 'children': ['307', '318', '340', '348']},{'id': '307', 'type': 'import_from_statement', 'children': ['308', '312', '314', '316']},{'id': '308', 'type': 'dotted_name', 'children': ['309', '310', '311']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'django'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'apps'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'registry'},{'id': '312', 'type': 'dotted_name', 'children': ['313']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'apps'},{'id': '314', 'type': 'dotted_name', 'children': ['315']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'Apps'},{'id': '316', 'type': 'dotted_name', 'children': ['317']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'AppRegistryNotReady'},{'id': '318', 'type': 'if_statement', 'children': ['319', '323', '331']},{'id': '319', 'type': 'not_operator', 'children': ['320']},{'id': '320', 'type': 'attribute', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'apps'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'apps_ready'},{'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': 'apps'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'populate'},{'id': '329', 'type': 'argument_list', 'children': ['330']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'installed_apps'},{'id': '331', 'type': 'else_clause', 'children': ['332']},{'id': '332', 'type': 'block', 'children': ['333']},{'id': '333', 'type': 'expression_statement', 'children': ['334']},{'id': '334', 'type': 'assignment', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'apps'},{'id': '336', 'type': 'call', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'Apps'},{'id': '338', 'type': 'argument_list', 'children': ['339']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'installed_apps'},{'id': '340', 'type': 'expression_statement', 'children': ['341']},{'id': '341', 'type': 'assignment', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '343', 'type': 'call', 'children': ['344', '347']},{'id': '344', 'type': 'attribute', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '347', 'type': 'argument_list', 'children': []},{'id': '348', 'type': 'while_statement', 'children': ['349', '350']},{'id': '349', 'type': 'True', 'children': []},{'id': '350', 'type': 'block', 'children': ['351', '397']},{'id': '351', 'type': 'try_statement', 'children': ['352', '370']},{'id': '352', 'type': 'block', 'children': ['353']},{'id': '353', 'type': 'for_statement', 'children': ['354', '355', '360']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '355', 'type': 'call', 'children': ['356', '359']},{'id': '356', 'type': 'attribute', 'children': ['357', '358']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'apps'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'get_app_configs'},{'id': '359', 'type': 'argument_list', 'children': []},{'id': '360', 'type': 'block', 'children': ['361']},{'id': '361', 'type': 'expression_statement', 'children': ['362']},{'id': '362', 'type': 'call', 'children': ['363', '366']},{'id': '363', 'type': 'attribute', 'children': ['364', '365']},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'installed_apps'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '366', 'type': 'argument_list', 'children': ['367']},{'id': '367', 'type': 'attribute', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '370', 'type': 'except_clause', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'AppRegistryNotReady'},{'id': '372', 'type': 'block', 'children': ['373', '389', '396']},{'id': '373', 'type': 'if_statement', 'children': ['374', '383']},{'id': '374', 'type': 'comparison_operator', 'children': ['375', '382'], 'value': '>'},{'id': '375', 'type': 'binary_operator', 'children': ['376', '381'], 'value': '-'},{'id': '376', 'type': 'call', 'children': ['377', '380']},{'id': '377', 'type': 'attribute', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '380', 'type': 'argument_list', 'children': []},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '382', 'type': 'integer', 'children': [], 'value': '10'},{'id': '383', 'type': 'block', 'children': ['384']},{'id': '384', 'type': 'raise_statement', 'children': ['385']},{'id': '385', 'type': 'call', 'children': ['386', '387']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '387', 'type': 'argument_list', 'children': ['388']},{'id': '388', 'type': 'string', 'children': [], 'value': "'Bail out of waiting for Django'"},{'id': '389', 'type': 'expression_statement', 'children': ['390']},{'id': '390', 'type': 'call', 'children': ['391', '394']},{'id': '391', 'type': 'attribute', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '394', 'type': 'argument_list', 'children': ['395']},{'id': '395', 'type': 'string', 'children': [], 'value': "'Waiting for apps to load...'"},{'id': '396', 'type': 'continue_statement', 'children': []},{'id': '397', 'type': 'break_statement', 'children': []},{'id': '398', 'type': 'except_clause', 'children': ['399', '403']},{'id': '399', 'type': 'as_pattern', 'children': ['400', '401']},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '401', 'type': 'as_pattern_target', 'children': ['402']},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '403', 'type': 'block', 'children': ['404']},{'id': '404', 'type': 'expression_statement', 'children': ['405']},{'id': '405', 'type': 'call', 'children': ['406', '409']},{'id': '406', 'type': 'attribute', 'children': ['407', '408']},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '409', 'type': 'argument_list', 'children': ['410']},{'id': '410', 'type': 'call', 'children': ['411', '414']},{'id': '411', 'type': 'attribute', 'children': ['412', '413']},{'id': '412', 'type': 'string', 'children': [], 'value': "'Could not use AppConfig: {}'"},{'id': '413', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '414', 'type': 'argument_list', 'children': ['415']},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '416', 'type': 'expression_statement', 'children': ['417']},{'id': '417', 'type': 'assignment', 'children': ['418', '424']},{'id': '418', 'type': 'subscript', 'children': ['419', '422']},{'id': '419', 'type': 'attribute', 'children': ['420', '421']},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '422', 'type': 'slice', 'children': ['423']},{'id': '423', 'type': 'colon', 'children': []},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'old_sys_path'},{'id': '425', 'type': 'expression_statement', 'children': ['426']},{'id': '426', 'type': 'call', 'children': ['427', '430']},{'id': '427', 'type': 'attribute', 'children': ['428', '429']},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '429', 'type': 'identifier', 'children': [], 'value': 'chdir'},{'id': '430', 'type': 'argument_list', 'children': ['431']},{'id': '431', 'type': 'identifier', 'children': [], 'value': 'cwd'},{'id': '432', 'type': 'for_statement', 'children': ['433', '434', '435']},{'id': '433', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '434', 'type': 'identifier', 'children': [], 'value': 'settings_imports'},{'id': '435', 'type': 'block', 'children': ['436', '445']},{'id': '436', 'type': 'expression_statement', 'children': ['437']},{'id': '437', 'type': 'assignment', 'children': ['438', '439']},{'id': '438', 'type': 'identifier', 'children': [], 'value': 'need_scan'},{'id': '439', 'type': 'call', 'children': ['440', '443']},{'id': '440', 'type': 'attribute', 'children': ['441', '442']},{'id': '441', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '442', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '443', 'type': 'argument_list', 'children': ['444']},{'id': '444', 'type': 'identifier', 'children': [], 'value': '_filescan_modules'},{'id': '445', 'type': 'expression_statement', 'children': ['446']},{'id': '446', 'type': 'yield', 'children': ['447']},{'id': '447', 'type': 'tuple', 'children': ['448', '449', '450']},{'id': '448', 'type': 'string', 'children': [], 'value': "'django'"},{'id': '449', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '450', 'type': 'conditional_expression', 'children': ['451', '452', '453'], 'value': 'if'},{'id': '451', 'type': 'identifier', 'children': [], 'value': 'project_path'},{'id': '452', 'type': 'identifier', 'children': [], 'value': 'need_scan'},{'id': '453', 'type': 'None', 'children': []},{'id': '454', 'type': 'for_statement', 'children': ['455', '456', '457']},{'id': '455', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '456', 'type': 'identifier', 'children': [], 'value': 'installed_apps'},{'id': '457', 'type': 'block', 'children': ['458', '467']},{'id': '458', 'type': 'expression_statement', 'children': ['459']},{'id': '459', 'type': 'assignment', 'children': ['460', '461']},{'id': '460', 'type': 'identifier', 'children': [], 'value': 'need_scan'},{'id': '461', 'type': 'call', 'children': ['462', '465']},{'id': '462', 'type': 'attribute', 'children': ['463', '464']},{'id': '463', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '464', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '465', 'type': 'argument_list', 'children': ['466']},{'id': '466', 'type': 'identifier', 'children': [], 'value': 'project'},{'id': '467', 'type': 'expression_statement', 'children': ['468']},{'id': '468', 'type': 'yield', 'children': ['469']},{'id': '469', 'type': 'tuple', 'children': ['470', '471', '472']},{'id': '470', 'type': 'string', 'children': [], 'value': "'django'"},{'id': '471', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '472', 'type': 'conditional_expression', 'children': ['473', '474', '475'], 'value': 'if'},{'id': '473', 'type': 'identifier', 'children': [], 'value': 'project_path'},{'id': '474', 'type': 'identifier', 'children': [], 'value': 'need_scan'},{'id': '475', 'type': 'None', 'children': []}
def handle_django_settings(filename): '''Attempts to load a Django project and get package dependencies from settings. Tested using Django 1.4 and 1.8. Not sure if some nuances are missed in the other versions. ''' old_sys_path = sys.path[:] dirpath = os.path.dirname(filename) project = os.path.basename(dirpath) cwd = os.getcwd() project_path = os.path.normpath(os.path.join(dirpath, '..')) if project_path not in sys.path: sys.path.insert(0, project_path) os.chdir(project_path) project_settings = '{}.settings'.format(project) os.environ['DJANGO_SETTINGS_MODULE'] = project_settings try: import django django.setup = lambda: False except ImportError: log.error('Found Django settings, but Django is not installed.') return log.warn('Loading Django Settings (Using {}): {}' .format(django.get_version(), filename)) from django.conf import LazySettings installed_apps = set() settings_imports = set() try: settings = LazySettings() settings._setup() for k, v in vars(settings._wrapped).items(): if k not in _excluded_settings and re.match(r'^[A-Z_]+$', k): scan_django_settings(v, settings_imports) for app in getattr(settings, 'INSTALLED_APPS', []): if hasattr(app, '__file__') and getattr(app, '__file__'): imp, _ = utils.import_path_from_file(getattr(app, '__file__')) installed_apps.add(imp) else: installed_apps.add(app) except Exception as e: log.error('Could not load Django settings: %s', e) log.debug('', exc_info=True) return if not installed_apps or not settings_imports: log.error('Got empty settings values from Django settings.') try: from django.apps.registry import apps, Apps, AppRegistryNotReady if not apps.apps_ready: apps.populate(installed_apps) else: apps = Apps(installed_apps) start = time.time() while True: try: for app in apps.get_app_configs(): installed_apps.add(app.name) except AppRegistryNotReady: if time.time() - start > 10: raise Exception('Bail out of waiting for Django') log.debug('Waiting for apps to load...') continue break except Exception as e: log.debug('Could not use AppConfig: {}'.format(e)) sys.path[:] = old_sys_path os.chdir(cwd) for item in settings_imports: need_scan = item.startswith(_filescan_modules) yield ('django', item, project_path if need_scan else None) for app in installed_apps: need_scan = app.startswith(project) yield ('django', app, project_path if need_scan else None)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '30']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'send_array'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'socket'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '13', 'type': 'integer', 'children': [], 'value': '0'},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '16', 'type': 'False', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'track'},{'id': '19', 'type': 'False', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'compress'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'chunksize'},{'id': '25', 'type': 'binary_operator', 'children': ['26', '29'], 'value': '*'},{'id': '26', 'type': 'binary_operator', 'children': ['27', '28'], 'value': '*'},{'id': '27', 'type': 'integer', 'children': [], 'value': '50'},{'id': '28', 'type': 'integer', 'children': [], 'value': '1000'},{'id': '29', 'type': 'integer', 'children': [], 'value': '1000'},{'id': '30', 'type': 'block', 'children': ['31', '35', '51', '61', '81', '103', '114', '122', '142', '169', '181', '278']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '34', 'type': 'dictionary', 'children': []},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '40']},{'id': '37', 'type': 'subscript', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '39', 'type': 'string', 'children': [], 'value': "'timestamp'"},{'id': '40', 'type': 'call', 'children': ['41', '50']},{'id': '41', 'type': 'attribute', 'children': ['42', '49']},{'id': '42', 'type': 'call', 'children': ['43', '48']},{'id': '43', 'type': 'attribute', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '48', 'type': 'argument_list', 'children': []},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'isoformat'},{'id': '50', 'type': 'argument_list', 'children': []},{'id': '51', 'type': 'if_statement', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'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': 'md'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '61', 'type': 'if_statement', 'children': ['62', '65']},{'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'is'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '64', 'type': 'None', 'children': []},{'id': '65', 'type': 'block', 'children': ['66', '72', '80']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '71']},{'id': '68', 'type': 'subscript', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '70', 'type': 'string', 'children': [], 'value': "'parts'"},{'id': '71', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'socket'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'send_json'},{'id': '77', 'type': 'argument_list', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '80', 'type': 'return_statement', 'children': []},{'id': '81', 'type': 'if_statement', 'children': ['82', '93']},{'id': '82', 'type': 'boolean_operator', 'children': ['83', '88'], 'value': 'or'},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '85', 'type': 'argument_list', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '108']},{'id': '105', 'type': 'subscript', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '107', 'type': 'string', 'children': [], 'value': "'dtype'"},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'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': 'md'},{'id': '118', 'type': 'string', 'children': [], 'value': "'shape'"},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '127']},{'id': '124', 'type': 'subscript', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '126', 'type': 'string', 'children': [], 'value': "'parts'"},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'binary_operator', 'children': ['131', '141'], 'value': '+'},{'id': '131', 'type': 'binary_operator', 'children': ['132', '140'], 'value': '//'},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'prod'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'chunksize'},{'id': '141', 'type': 'integer', 'children': [], 'value': '1'},{'id': '142', 'type': 'try_statement', 'children': ['143', '165']},{'id': '143', 'type': 'block', 'children': ['144', '157']},{'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': 'md'},{'id': '148', 'type': 'string', 'children': [], 'value': "'fill_value'"},{'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': 'asscalar'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'fill_value'},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'filled'},{'id': '164', 'type': 'argument_list', 'children': []},{'id': '165', 'type': 'except_clause', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'pass_statement', 'children': []},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'socket'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'send_json'},{'id': '174', 'type': 'argument_list', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '176', 'type': 'binary_operator', 'children': ['177', '178'], 'value': '|'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'zmq'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'SNDMORE'},{'id': '181', 'type': 'if_statement', 'children': ['182', '187', '214']},{'id': '182', 'type': 'comparison_operator', 'children': ['183', '186'], 'value': '=='},{'id': '183', 'type': 'subscript', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '185', 'type': 'string', 'children': [], 'value': "'parts'"},{'id': '186', 'type': 'integer', 'children': [], 'value': '1'},{'id': '187', 'type': 'block', 'children': ['188', '200']},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '191', 'type': 'call', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'memoryview'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'ascontiguousarray'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'A'},{'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': 'socket'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '205', 'type': 'argument_list', 'children': ['206', '207', '208', '211']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '208', 'type': 'keyword_argument', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '211', 'type': 'keyword_argument', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'track'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'track'},{'id': '214', 'type': 'else_clause', 'children': ['215']},{'id': '215', 'type': 'block', 'children': ['216']},{'id': '216', 'type': 'for_statement', 'children': ['217', '220', '232']},{'id': '217', 'type': 'pattern_list', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '220', 'type': 'call', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'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': 'np'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'array_split'},{'id': '227', 'type': 'argument_list', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '229', 'type': 'subscript', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '231', 'type': 'string', 'children': [], 'value': "'parts'"},{'id': '232', 'type': 'block', 'children': ['233', '245', '249', '264']},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'assignment', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '236', 'type': 'call', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'memoryview'},{'id': '238', 'type': 'argument_list', 'children': ['239']},{'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': 'ascontiguousarray'},{'id': '243', 'type': 'argument_list', 'children': ['244']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'assignment', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'flags_'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '249', 'type': 'if_statement', 'children': ['250', '257']},{'id': '250', 'type': 'comparison_operator', 'children': ['251', '252'], 'value': '!='},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '252', 'type': 'binary_operator', 'children': ['253', '256'], 'value': '-'},{'id': '253', 'type': 'subscript', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '255', 'type': 'string', 'children': [], 'value': "'parts'"},{'id': '256', 'type': 'integer', 'children': [], 'value': '1'},{'id': '257', 'type': 'block', 'children': ['258']},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'augmented_assignment', 'children': ['260', '261'], 'value': '|='},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'flags_'},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'zmq'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'SNDMORE'},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'call', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'socket'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '269', 'type': 'argument_list', 'children': ['270', '271', '272', '275']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'flags_'},{'id': '272', 'type': 'keyword_argument', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '275', 'type': 'keyword_argument', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'track'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'track'},{'id': '278', 'type': 'return_statement', 'children': []}
def send_array( socket, A=None, metadata=None, flags=0, copy=False, track=False, compress=None, chunksize=50 * 1000 * 1000 ): md = {} md['timestamp'] = datetime.datetime.now().isoformat() if metadata: md.update(metadata) if A is None: md['parts'] = 0 socket.send_json(md, flags) return if isinstance(A, float) or isinstance(A, int): A = np.asarray(A) md['dtype'] = str(A.dtype) md['shape'] = A.shape md['parts'] = int(np.prod(A.shape) // chunksize + 1) try: md['fill_value'] = np.asscalar(A.fill_value) A = A.filled() except AttributeError: pass socket.send_json(md, flags | zmq.SNDMORE) if md['parts'] == 1: msg = memoryview(np.ascontiguousarray(A)) socket.send(msg, flags, copy=copy, track=track) else: for i, a in enumerate(np.array_split(A, md['parts'])): msg = memoryview(np.ascontiguousarray(a)) flags_ = flags if i != md['parts'] - 1: flags_ |= zmq.SNDMORE socket.send(msg, flags_, copy=copy, track=track) return
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'recv_array'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'socket'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '7', 'type': 'integer', 'children': [], 'value': '0'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'track'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'poll'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'poll_timeout'},{'id': '19', 'type': 'integer', 'children': [], 'value': '10000'},{'id': '20', 'type': 'block', 'children': ['21', '85', '428']},{'id': '21', 'type': 'if_statement', 'children': ['22', '25', '37']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'is'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'poll'},{'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': 'md'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'socket'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'recv_json'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '37', 'type': 'else_clause', 'children': ['38']},{'id': '38', 'type': 'block', 'children': ['39', '51']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'socks'},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'poll'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'poll'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'poll_timeout'},{'id': '51', 'type': 'if_statement', 'children': ['52', '62', '78']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '59'], 'value': '=='},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'socks'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'socket'},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'zmq'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'POLLIN'},{'id': '62', 'type': 'block', 'children': ['63', '74']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'reply'},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'socket'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'recv_json'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'reply'},{'id': '78', 'type': 'else_clause', 'children': ['79']},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'raise_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'NoResponseException'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'string', 'children': [], 'value': '"Recv_array got no response within timeout (1)"'},{'id': '85', 'type': 'if_statement', 'children': ['86', '91', '96', '230']},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '90'], 'value': '=='},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '89', 'type': 'string', 'children': [], 'value': "'parts'"},{'id': '90', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'A'},{'id': '95', 'type': 'None', 'children': []},{'id': '96', 'type': 'elif_clause', 'children': ['97', '102']},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '101'], 'value': '=='},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '100', 'type': 'string', 'children': [], 'value': "'parts'"},{'id': '101', 'type': 'integer', 'children': [], 'value': '1'},{'id': '102', 'type': 'block', 'children': ['103', '179', '186', '200', '211']},{'id': '103', 'type': 'if_statement', 'children': ['104', '107', '125']},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '106'], 'value': 'is'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'poll'},{'id': '106', 'type': 'None', 'children': []},{'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': 'msg'},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'socket'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'recv'},{'id': '115', 'type': 'argument_list', 'children': ['116', '119', '122']},{'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'track'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'track'},{'id': '125', 'type': 'else_clause', 'children': ['126']},{'id': '126', 'type': 'block', 'children': ['127', '139']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'socks'},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'poll'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'poll'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'poll_timeout'},{'id': '139', 'type': 'if_statement', 'children': ['140', '150', '172']},{'id': '140', 'type': 'comparison_operator', 'children': ['141', '147'], 'value': '=='},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'socks'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'socket'},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'zmq'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'POLLIN'},{'id': '150', 'type': 'block', 'children': ['151', '168']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'reply'},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'socket'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'recv'},{'id': '158', 'type': 'argument_list', 'children': ['159', '162', '165']},{'id': '159', 'type': 'keyword_argument', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '162', 'type': 'keyword_argument', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '165', 'type': 'keyword_argument', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'track'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'track'},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'reply'},{'id': '172', 'type': 'else_clause', 'children': ['173']},{'id': '173', 'type': 'block', 'children': ['174']},{'id': '174', 'type': 'raise_statement', 'children': ['175']},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'NoResponseException'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'string', 'children': [], 'value': '"Recv_array got no response within timeout (2)"'},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'buffer'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '189', 'type': 'call', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'frombuffer'},{'id': '193', 'type': 'argument_list', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '195', 'type': 'keyword_argument', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '197', 'type': 'subscript', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '199', 'type': 'string', 'children': [], 'value': "'dtype'"},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '203', 'type': 'call', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'reshape'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'subscript', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '210', 'type': 'string', 'children': [], 'value': "'shape'"},{'id': '211', 'type': 'if_statement', 'children': ['212', '215']},{'id': '212', 'type': 'comparison_operator', 'children': ['213', '214'], 'value': 'in'},{'id': '213', 'type': 'string', 'children': [], 'value': "'fill_value'"},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '215', 'type': 'block', 'children': ['216']},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'assignment', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '219', 'type': 'call', 'children': ['220', '225']},{'id': '220', 'type': 'attribute', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'ma'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'masked_equal'},{'id': '225', 'type': 'argument_list', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '227', 'type': 'subscript', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '229', 'type': 'string', 'children': [], 'value': "'fill_value'"},{'id': '230', 'type': 'else_clause', 'children': ['231']},{'id': '231', 'type': 'block', 'children': ['232', '253', '257', '398', '409']},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '235', 'type': 'call', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '239', 'type': 'argument_list', 'children': ['240', '248']},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'prod'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'subscript', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '247', 'type': 'string', 'children': [], 'value': "'shape'"},{'id': '248', 'type': 'keyword_argument', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '250', 'type': 'subscript', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '252', 'type': 'string', 'children': [], 'value': "'dtype'"},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'assignment', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'arr_position'},{'id': '256', 'type': 'integer', 'children': [], 'value': '0'},{'id': '257', 'type': 'for_statement', 'children': ['258', '259', '265']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '259', 'type': 'call', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '261', 'type': 'argument_list', 'children': ['262']},{'id': '262', 'type': 'subscript', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '264', 'type': 'string', 'children': [], 'value': "'parts'"},{'id': '265', 'type': 'block', 'children': ['266', '351', '358', '372', '390']},{'id': '266', 'type': 'if_statement', 'children': ['267', '270', '288']},{'id': '267', 'type': 'comparison_operator', 'children': ['268', '269'], 'value': 'is'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'poll'},{'id': '269', 'type': 'None', 'children': []},{'id': '270', 'type': 'block', 'children': ['271']},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'assignment', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '274', 'type': 'call', 'children': ['275', '278']},{'id': '275', 'type': 'attribute', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'socket'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'recv'},{'id': '278', 'type': 'argument_list', 'children': ['279', '282', '285']},{'id': '279', 'type': 'keyword_argument', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '282', 'type': 'keyword_argument', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '285', 'type': 'keyword_argument', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'track'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'track'},{'id': '288', 'type': 'else_clause', 'children': ['289']},{'id': '289', 'type': 'block', 'children': ['290', '302']},{'id': '290', 'type': 'expression_statement', 'children': ['291']},{'id': '291', 'type': 'assignment', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'socks'},{'id': '293', 'type': 'call', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '295', 'type': 'argument_list', 'children': ['296']},{'id': '296', 'type': 'call', 'children': ['297', '300']},{'id': '297', 'type': 'attribute', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'poll'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'poll'},{'id': '300', 'type': 'argument_list', 'children': ['301']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'poll_timeout'},{'id': '302', 'type': 'if_statement', 'children': ['303', '313', '344']},{'id': '303', 'type': 'comparison_operator', 'children': ['304', '310'], 'value': '=='},{'id': '304', 'type': 'call', 'children': ['305', '308']},{'id': '305', 'type': 'attribute', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'socks'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '308', 'type': 'argument_list', 'children': ['309']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'socket'},{'id': '310', 'type': 'attribute', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'zmq'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'POLLIN'},{'id': '313', 'type': 'block', 'children': ['314', '331', '340']},{'id': '314', 'type': 'expression_statement', 'children': ['315']},{'id': '315', 'type': 'assignment', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'reply'},{'id': '317', 'type': 'call', 'children': ['318', '321']},{'id': '318', 'type': 'attribute', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'socket'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'recv'},{'id': '321', 'type': 'argument_list', 'children': ['322', '325', '328']},{'id': '322', 'type': 'keyword_argument', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '325', 'type': 'keyword_argument', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '328', 'type': 'keyword_argument', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'track'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'track'},{'id': '331', 'type': 'if_statement', 'children': ['332', '334']},{'id': '332', 'type': 'not_operator', 'children': ['333']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'reply'},{'id': '334', 'type': 'block', 'children': ['335']},{'id': '335', 'type': 'raise_statement', 'children': ['336']},{'id': '336', 'type': 'call', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'EmptyResponseException'},{'id': '338', 'type': 'argument_list', 'children': ['339']},{'id': '339', 'type': 'string', 'children': [], 'value': '"Recv_array got an empty response (2)"'},{'id': '340', 'type': 'expression_statement', 'children': ['341']},{'id': '341', 'type': 'assignment', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'reply'},{'id': '344', 'type': 'else_clause', 'children': ['345']},{'id': '345', 'type': 'block', 'children': ['346']},{'id': '346', 'type': 'raise_statement', 'children': ['347']},{'id': '347', 'type': 'call', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'NoResponseException'},{'id': '349', 'type': 'argument_list', 'children': ['350']},{'id': '350', 'type': 'string', 'children': [], 'value': '"Recv_array got no response within timeout (2)"'},{'id': '351', 'type': 'expression_statement', 'children': ['352']},{'id': '352', 'type': 'assignment', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '354', 'type': 'call', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'buffer'},{'id': '356', 'type': 'argument_list', 'children': ['357']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '358', 'type': 'expression_statement', 'children': ['359']},{'id': '359', 'type': 'assignment', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '361', 'type': 'call', 'children': ['362', '365']},{'id': '362', 'type': 'attribute', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'frombuffer'},{'id': '365', 'type': 'argument_list', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '367', 'type': 'keyword_argument', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '369', 'type': 'subscript', 'children': ['370', '371']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '371', 'type': 'string', 'children': [], 'value': "'dtype'"},{'id': '372', 'type': 'expression_statement', 'children': ['373']},{'id': '373', 'type': 'assignment', 'children': ['374', '386']},{'id': '374', 'type': 'subscript', 'children': ['375', '376']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '376', 'type': 'slice', 'children': ['377', '378', '379']},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'arr_position'},{'id': '378', 'type': 'colon', 'children': []},{'id': '379', 'type': 'binary_operator', 'children': ['380', '381'], 'value': '+'},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'arr_position'},{'id': '381', 'type': 'subscript', 'children': ['382', '385']},{'id': '382', 'type': 'attribute', 'children': ['383', '384']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '385', 'type': 'integer', 'children': [], 'value': '0'},{'id': '386', 'type': 'subscript', 'children': ['387', '388']},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '388', 'type': 'slice', 'children': ['389']},{'id': '389', 'type': 'colon', 'children': []},{'id': '390', 'type': 'expression_statement', 'children': ['391']},{'id': '391', 'type': 'augmented_assignment', 'children': ['392', '393'], 'value': '+='},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'arr_position'},{'id': '393', 'type': 'subscript', 'children': ['394', '397']},{'id': '394', 'type': 'attribute', 'children': ['395', '396']},{'id': '395', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '397', 'type': 'integer', 'children': [], 'value': '0'},{'id': '398', 'type': 'expression_statement', 'children': ['399']},{'id': '399', 'type': 'assignment', 'children': ['400', '401']},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '401', 'type': 'call', 'children': ['402', '405']},{'id': '402', 'type': 'attribute', 'children': ['403', '404']},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'reshape'},{'id': '405', 'type': 'argument_list', 'children': ['406']},{'id': '406', 'type': 'subscript', 'children': ['407', '408']},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '408', 'type': 'string', 'children': [], 'value': "'shape'"},{'id': '409', 'type': 'if_statement', 'children': ['410', '413']},{'id': '410', 'type': 'comparison_operator', 'children': ['411', '412'], 'value': 'in'},{'id': '411', 'type': 'string', 'children': [], 'value': "'fill_value'"},{'id': '412', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '413', 'type': 'block', 'children': ['414']},{'id': '414', 'type': 'expression_statement', 'children': ['415']},{'id': '415', 'type': 'assignment', 'children': ['416', '417']},{'id': '416', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '417', 'type': 'call', 'children': ['418', '423']},{'id': '418', 'type': 'attribute', 'children': ['419', '422']},{'id': '419', 'type': 'attribute', 'children': ['420', '421']},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'ma'},{'id': '422', 'type': 'identifier', 'children': [], 'value': 'masked_equal'},{'id': '423', 'type': 'argument_list', 'children': ['424', '425']},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '425', 'type': 'subscript', 'children': ['426', '427']},{'id': '426', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '427', 'type': 'string', 'children': [], 'value': "'fill_value'"},{'id': '428', 'type': 'return_statement', 'children': ['429']},{'id': '429', 'type': 'expression_list', 'children': ['430', '431']},{'id': '430', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '431', 'type': 'identifier', 'children': [], 'value': 'md'}
def recv_array( socket, flags=0, copy=False, track=False, poll=None, poll_timeout=10000 ): if poll is None: md = socket.recv_json(flags=flags) else: socks = dict(poll.poll(poll_timeout)) if socks.get(socket) == zmq.POLLIN: reply = socket.recv_json(flags=flags) md = reply else: raise NoResponseException( "Recv_array got no response within timeout (1)") if md['parts'] == 0: A = None elif md['parts'] == 1: if poll is None: msg = socket.recv(flags=flags, copy=copy, track=track) else: socks = dict(poll.poll(poll_timeout)) if socks.get(socket) == zmq.POLLIN: reply = socket.recv(flags=flags, copy=copy, track=track) msg = reply else: raise NoResponseException( "Recv_array got no response within timeout (2)") buf = buffer(msg) A = np.frombuffer(buf, dtype=md['dtype']) A = A.reshape(md['shape']) if 'fill_value' in md: A = np.ma.masked_equal(A, md['fill_value']) else: A = np.zeros(np.prod(md['shape']), dtype=md['dtype']) arr_position = 0 for i in range(md['parts']): if poll is None: msg = socket.recv(flags=flags, copy=copy, track=track) else: socks = dict(poll.poll(poll_timeout)) if socks.get(socket) == zmq.POLLIN: reply = socket.recv(flags=flags, copy=copy, track=track) if not reply: raise EmptyResponseException( "Recv_array got an empty response (2)") msg = reply else: raise NoResponseException( "Recv_array got no response within timeout (2)") buf = buffer(msg) a = np.frombuffer(buf, dtype=md['dtype']) A[arr_position:arr_position + a.shape[0]] = a[:] arr_position += a.shape[0] A = A.reshape(md['shape']) if 'fill_value' in md: A = np.ma.masked_equal(A, md['fill_value']) return A, md
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'reduce_fit'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'interface'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'inp'},{'id': '8', 'type': 'block', 'children': ['9', '15', '20', '29', '44', '48', '56', '60', '301', '395', '414', '432', '445', '458']},{'id': '9', 'type': 'import_from_statement', 'children': ['10', '13']},{'id': '10', 'type': 'dotted_name', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'disco'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'util'},{'id': '13', 'type': 'dotted_name', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'kvgroup'},{'id': '15', 'type': 'import_statement', 'children': ['16']},{'id': '16', 'type': 'aliased_import', 'children': ['17', '19']},{'id': '17', 'type': 'dotted_name', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'interface'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'integer', 'children': [], 'value': '0'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'fit_model'},{'id': '32', 'type': 'dictionary', 'children': ['33', '36', '39']},{'id': '33', 'type': 'pair', 'children': ['34', '35']},{'id': '34', 'type': 'string', 'children': [], 'value': '"y_labels"'},{'id': '35', 'type': 'list', 'children': [], 'value': '[]'},{'id': '36', 'type': 'pair', 'children': ['37', '38']},{'id': '37', 'type': 'string', 'children': [], 'value': '"y_sum"'},{'id': '38', 'type': 'integer', 'children': [], 'value': '0'},{'id': '39', 'type': 'pair', 'children': ['40', '41']},{'id': '40', 'type': 'string', 'children': [], 'value': '"iv"'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '43', 'type': 'argument_list', 'children': []},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'combiner'},{'id': '47', 'type': 'dictionary', 'children': []},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '53']},{'id': '50', 'type': 'pattern_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'means'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'variances'},{'id': '53', 'type': 'expression_list', 'children': ['54', '55']},{'id': '54', 'type': 'list', 'children': [], 'value': '[]'},{'id': '55', 'type': 'list', 'children': [], 'value': '[]'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'k_prev'},{'id': '59', 'type': 'string', 'children': [], 'value': '""'},{'id': '60', 'type': 'for_statement', 'children': ['61', '64', '68']},{'id': '61', 'type': 'pattern_list', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'kvgroup'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'inp'},{'id': '68', 'type': 'block', 'children': ['69', '80']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'k_split'},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '79', 'type': 'string', 'children': [], 'value': '"delimiter"'},{'id': '80', 'type': 'if_statement', 'children': ['81', '87', '118', '271']},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '86'], 'value': '=='},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'k_split'},{'id': '86', 'type': 'integer', 'children': [], 'value': '3'},{'id': '87', 'type': 'block', 'children': ['88', '104']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '95']},{'id': '90', 'type': 'attribute', 'children': ['91', '94']},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'fit_model'},{'id': '93', 'type': 'string', 'children': [], 'value': '"iv"'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'subscript', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'k_split'},{'id': '101', 'type': 'slice', 'children': ['102', '103']},{'id': '102', 'type': 'integer', 'children': [], 'value': '1'},{'id': '103', 'type': 'colon', 'children': []},{'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': 'out'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '109', 'type': 'argument_list', 'children': ['110', '114']},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'k_split'},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '118', 'type': 'elif_clause', 'children': ['119', '125']},{'id': '119', 'type': 'comparison_operator', 'children': ['120', '124'], 'value': '=='},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'k_split'},{'id': '124', 'type': 'integer', 'children': [], 'value': '2'},{'id': '125', 'type': 'block', 'children': ['126', '174', '182', '250', '265']},{'id': '126', 'type': 'if_statement', 'children': ['127', '136']},{'id': '127', 'type': 'boolean_operator', 'children': ['128', '133'], 'value': 'and'},{'id': '128', 'type': 'comparison_operator', 'children': ['129', '132'], 'value': '!='},{'id': '129', 'type': 'subscript', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'k_split'},{'id': '131', 'type': 'integer', 'children': [], 'value': '0'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'k_prev'},{'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': '!='},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'k_prev'},{'id': '135', 'type': 'string', 'children': [], 'value': '""'},{'id': '136', 'type': 'block', 'children': ['137', '160', '167']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '142']},{'id': '139', 'type': 'pattern_list', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'mean'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'list_splat', 'children': ['146']},{'id': '146', 'type': 'list_comprehension', 'children': ['147', '150']},{'id': '147', 'type': 'subscript', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'combiner'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '150', 'type': 'for_in_clause', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'combiner'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '159', 'type': 'argument_list', 'children': []},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'means'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'mean'},{'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': 'variances'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'n_a'},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'mean_a'},{'id': '179', 'type': 'assignment', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'var_a'},{'id': '181', 'type': 'integer', 'children': [], 'value': '0'},{'id': '182', 'type': 'for_statement', 'children': ['183', '187', '188']},{'id': '183', 'type': 'pattern_list', 'children': ['184', '185', '186']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'n_b'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'mean_b'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'var_b'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '188', 'type': 'block', 'children': ['189', '195', '230', '246']},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'n_ab'},{'id': '192', 'type': 'binary_operator', 'children': ['193', '194'], 'value': '+'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'n_a'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'n_b'},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'var_a'},{'id': '198', 'type': 'binary_operator', 'children': ['199', '213'], 'value': '+'},{'id': '199', 'type': '()', 'children': ['200']},{'id': '200', 'type': 'binary_operator', 'children': ['201', '209'], 'value': '/'},{'id': '201', 'type': '()', 'children': ['202']},{'id': '202', 'type': 'binary_operator', 'children': ['203', '206'], 'value': '+'},{'id': '203', 'type': 'binary_operator', 'children': ['204', '205'], 'value': '*'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'n_a'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'var_a'},{'id': '206', 'type': 'binary_operator', 'children': ['207', '208'], 'value': '*'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'n_b'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'var_b'},{'id': '209', 'type': 'call', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'n_ab'},{'id': '213', 'type': '()', 'children': ['214']},{'id': '214', 'type': 'binary_operator', 'children': ['215', '218'], 'value': '*'},{'id': '215', 'type': 'binary_operator', 'children': ['216', '217'], 'value': '*'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'n_a'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'n_b'},{'id': '218', 'type': 'binary_operator', 'children': ['219', '229'], 'value': '**'},{'id': '219', 'type': '()', 'children': ['220']},{'id': '220', 'type': 'binary_operator', 'children': ['221', '225'], 'value': '/'},{'id': '221', 'type': '()', 'children': ['222']},{'id': '222', 'type': 'binary_operator', 'children': ['223', '224'], 'value': '-'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'mean_b'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'mean_a'},{'id': '225', 'type': 'call', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'n_ab'},{'id': '229', 'type': 'integer', 'children': [], 'value': '2'},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'assignment', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'mean_a'},{'id': '233', 'type': 'binary_operator', 'children': ['234', '242'], 'value': '/'},{'id': '234', 'type': '()', 'children': ['235']},{'id': '235', 'type': 'binary_operator', 'children': ['236', '239'], 'value': '+'},{'id': '236', 'type': 'binary_operator', 'children': ['237', '238'], 'value': '*'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'n_a'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'mean_a'},{'id': '239', 'type': 'binary_operator', 'children': ['240', '241'], 'value': '*'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'n_b'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'mean_b'},{'id': '242', 'type': 'call', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'n_ab'},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'n_a'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'n_ab'},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'assignment', 'children': ['252', '260']},{'id': '252', 'type': 'subscript', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'combiner'},{'id': '254', 'type': 'call', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '256', 'type': 'argument_list', 'children': ['257']},{'id': '257', 'type': 'subscript', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'k_split'},{'id': '259', 'type': 'integer', 'children': [], 'value': '1'},{'id': '260', 'type': 'tuple', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'mean_a'},{'id': '262', 'type': 'binary_operator', 'children': ['263', '264'], 'value': '+'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'var_a'},{'id': '264', 'type': 'float', 'children': [], 'value': '1e-9'},{'id': '265', 'type': 'expression_statement', 'children': ['266']},{'id': '266', 'type': 'assignment', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'k_prev'},{'id': '268', 'type': 'subscript', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'k_split'},{'id': '270', 'type': 'integer', 'children': [], 'value': '0'},{'id': '271', 'type': 'else_clause', 'children': ['272']},{'id': '272', 'type': 'block', 'children': ['273', '284', '292']},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'assignment', 'children': ['275', '278']},{'id': '275', 'type': 'subscript', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'fit_model'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '278', 'type': 'call', 'children': ['279', '282']},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '282', 'type': 'argument_list', 'children': ['283']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '284', 'type': 'expression_statement', 'children': ['285']},{'id': '285', 'type': 'augmented_assignment', 'children': ['286', '289'], 'value': '+='},{'id': '286', 'type': 'subscript', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'fit_model'},{'id': '288', 'type': 'string', 'children': [], 'value': '"y_sum"'},{'id': '289', 'type': 'subscript', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'fit_model'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '292', 'type': 'expression_statement', 'children': ['293']},{'id': '293', 'type': 'call', 'children': ['294', '299']},{'id': '294', 'type': 'attribute', 'children': ['295', '298']},{'id': '295', 'type': 'subscript', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'fit_model'},{'id': '297', 'type': 'string', 'children': [], 'value': '"y_labels"'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '299', 'type': 'argument_list', 'children': ['300']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '301', 'type': 'if_statement', 'children': ['302', '308']},{'id': '302', 'type': 'comparison_operator', 'children': ['303', '307'], 'value': '>'},{'id': '303', 'type': 'call', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '305', 'type': 'argument_list', 'children': ['306']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'means'},{'id': '307', 'type': 'integer', 'children': [], 'value': '0'},{'id': '308', 'type': 'block', 'children': ['309', '332', '353', '370', '378']},{'id': '309', 'type': 'expression_statement', 'children': ['310']},{'id': '310', 'type': 'assignment', 'children': ['311', '314']},{'id': '311', 'type': 'pattern_list', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'mean'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '314', 'type': 'call', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '316', 'type': 'argument_list', 'children': ['317']},{'id': '317', 'type': 'list_splat', 'children': ['318']},{'id': '318', 'type': 'list_comprehension', 'children': ['319', '322']},{'id': '319', 'type': 'subscript', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'combiner'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '322', 'type': 'for_in_clause', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '324', 'type': 'call', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '326', 'type': 'argument_list', 'children': ['327']},{'id': '327', 'type': 'call', 'children': ['328', '331']},{'id': '328', 'type': 'attribute', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'combiner'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '331', 'type': 'argument_list', 'children': []},{'id': '332', 'type': 'expression_statement', 'children': ['333']},{'id': '333', 'type': 'call', 'children': ['334', '337']},{'id': '334', 'type': 'attribute', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '337', 'type': 'argument_list', 'children': ['338', '339']},{'id': '338', 'type': 'string', 'children': [], 'value': '"mean"'},{'id': '339', 'type': 'call', 'children': ['340', '343']},{'id': '340', 'type': 'attribute', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '343', 'type': 'argument_list', 'children': ['344', '348']},{'id': '344', 'type': 'binary_operator', 'children': ['345', '346'], 'value': '+'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'means'},{'id': '346', 'type': 'list', 'children': ['347'], 'value': '[mean]'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'mean'},{'id': '348', 'type': 'keyword_argument', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '350', 'type': 'attribute', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'float32'},{'id': '353', 'type': 'expression_statement', 'children': ['354']},{'id': '354', 'type': 'assignment', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'variances'},{'id': '356', 'type': 'call', 'children': ['357', '360']},{'id': '357', 'type': 'attribute', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '360', 'type': 'argument_list', 'children': ['361', '365']},{'id': '361', 'type': 'binary_operator', 'children': ['362', '363'], 'value': '+'},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'variances'},{'id': '363', 'type': 'list', 'children': ['364'], 'value': '[var]'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '365', 'type': 'keyword_argument', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '367', 'type': 'attribute', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'float32'},{'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': 'out'},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '375', 'type': 'argument_list', 'children': ['376', '377']},{'id': '376', 'type': 'string', 'children': [], 'value': '"var"'},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'variances'},{'id': '378', 'type': 'expression_statement', 'children': ['379']},{'id': '379', 'type': 'call', 'children': ['380', '383']},{'id': '380', 'type': 'attribute', 'children': ['381', '382']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '383', 'type': 'argument_list', 'children': ['384', '385']},{'id': '384', 'type': 'string', 'children': [], 'value': '"var_log"'},{'id': '385', 'type': 'call', 'children': ['386', '389']},{'id': '386', 'type': 'attribute', 'children': ['387', '388']},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '389', 'type': 'argument_list', 'children': ['390']},{'id': '390', 'type': 'binary_operator', 'children': ['391', '394'], 'value': '*'},{'id': '391', 'type': 'attribute', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'pi'},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'variances'},{'id': '395', 'type': 'expression_statement', 'children': ['396']},{'id': '396', 'type': 'assignment', 'children': ['397', '398']},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'prior'},{'id': '398', 'type': 'list_comprehension', 'children': ['399', '409']},{'id': '399', 'type': 'binary_operator', 'children': ['400', '403'], 'value': '/'},{'id': '400', 'type': 'subscript', 'children': ['401', '402']},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'fit_model'},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'y_label'},{'id': '403', 'type': 'call', 'children': ['404', '405']},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '405', 'type': 'argument_list', 'children': ['406']},{'id': '406', 'type': 'subscript', 'children': ['407', '408']},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'fit_model'},{'id': '408', 'type': 'string', 'children': [], 'value': '"y_sum"'},{'id': '409', 'type': 'for_in_clause', 'children': ['410', '411']},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'y_label'},{'id': '411', 'type': 'subscript', 'children': ['412', '413']},{'id': '412', 'type': 'identifier', 'children': [], 'value': 'fit_model'},{'id': '413', 'type': 'string', 'children': [], 'value': '"y_labels"'},{'id': '414', 'type': 'expression_statement', 'children': ['415']},{'id': '415', 'type': 'call', 'children': ['416', '419']},{'id': '416', 'type': 'attribute', 'children': ['417', '418']},{'id': '417', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '418', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '419', 'type': 'argument_list', 'children': ['420', '421']},{'id': '420', 'type': 'string', 'children': [], 'value': '"prior"'},{'id': '421', 'type': 'call', 'children': ['422', '425']},{'id': '422', 'type': 'attribute', 'children': ['423', '424']},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '425', 'type': 'argument_list', 'children': ['426', '427']},{'id': '426', 'type': 'identifier', 'children': [], 'value': 'prior'},{'id': '427', 'type': 'keyword_argument', 'children': ['428', '429']},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '429', 'type': 'attribute', 'children': ['430', '431']},{'id': '430', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '431', 'type': 'identifier', 'children': [], 'value': 'float32'},{'id': '432', 'type': 'expression_statement', 'children': ['433']},{'id': '433', 'type': 'call', 'children': ['434', '437']},{'id': '434', 'type': 'attribute', 'children': ['435', '436']},{'id': '435', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '436', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '437', 'type': 'argument_list', 'children': ['438', '439']},{'id': '438', 'type': 'string', 'children': [], 'value': '"prior_log"'},{'id': '439', 'type': 'call', 'children': ['440', '443']},{'id': '440', 'type': 'attribute', 'children': ['441', '442']},{'id': '441', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '442', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '443', 'type': 'argument_list', 'children': ['444']},{'id': '444', 'type': 'identifier', 'children': [], 'value': 'prior'},{'id': '445', 'type': 'expression_statement', 'children': ['446']},{'id': '446', 'type': 'call', 'children': ['447', '450']},{'id': '447', 'type': 'attribute', 'children': ['448', '449']},{'id': '448', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '449', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '450', 'type': 'argument_list', 'children': ['451', '452']},{'id': '451', 'type': 'string', 'children': [], 'value': '"iv"'},{'id': '452', 'type': 'call', 'children': ['453', '454']},{'id': '453', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '454', 'type': 'argument_list', 'children': ['455']},{'id': '455', 'type': 'subscript', 'children': ['456', '457']},{'id': '456', 'type': 'identifier', 'children': [], 'value': 'fit_model'},{'id': '457', 'type': 'string', 'children': [], 'value': '"iv"'},{'id': '458', 'type': 'expression_statement', 'children': ['459']},{'id': '459', 'type': 'call', 'children': ['460', '463']},{'id': '460', 'type': 'attribute', 'children': ['461', '462']},{'id': '461', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '462', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '463', 'type': 'argument_list', 'children': ['464', '465']},{'id': '464', 'type': 'string', 'children': [], 'value': '"y_labels"'},{'id': '465', 'type': 'subscript', 'children': ['466', '467']},{'id': '466', 'type': 'identifier', 'children': [], 'value': 'fit_model'},{'id': '467', 'type': 'string', 'children': [], 'value': '"y_labels"'}
def reduce_fit(interface, state, label, inp): from disco.util import kvgroup import numpy as np out = interface.output(0) fit_model = {"y_labels": [], "y_sum": 0, "iv": set()} combiner = {} means, variances = [], [] k_prev = "" for key, value in kvgroup(inp): k_split = key.split(state["delimiter"]) if len(k_split) == 3: fit_model["iv"].add(tuple(k_split[1:])) out.add(tuple(k_split), sum(value)) elif len(k_split) == 2: if k_split[0] != k_prev and k_prev != "": mean, var = zip(*[combiner[key] for key in sorted(combiner.keys())]) means.append(mean) variances.append(var) n_a = mean_a = var_a = 0 for n_b, mean_b, var_b in value: n_ab = n_a + n_b var_a = ((n_a * var_a + n_b * var_b) / float(n_ab)) + ( n_a * n_b * ((mean_b - mean_a) / float(n_ab)) ** 2) mean_a = (n_a * mean_a + n_b * mean_b) / float(n_ab) n_a = n_ab combiner[int(k_split[1])] = (mean_a, var_a + 1e-9) k_prev = k_split[0] else: fit_model[key] = np.sum(value) fit_model["y_sum"] += fit_model[key] fit_model["y_labels"].append(key) if len(means) > 0: mean, var = zip(*[combiner[key] for key in sorted(combiner.keys())]) out.add("mean", np.array(means + [mean], dtype=np.float32)) variances = np.array(variances + [var], dtype=np.float32) out.add("var", variances) out.add("var_log", np.log(np.pi * variances)) prior = [fit_model[y_label] / float(fit_model["y_sum"]) for y_label in fit_model["y_labels"]] out.add("prior", np.array(prior, dtype=np.float32)) out.add("prior_log", np.log(prior)) out.add("iv", list(fit_model["iv"])) out.add("y_labels", fit_model["y_labels"])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'map_predict'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'interface'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'inp'},{'id': '8', 'type': 'block', 'children': ['9', '14', '23', '46', '69', '81', '93']},{'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': 'out'},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'interface'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'integer', 'children': [], 'value': '0'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'continuous'},{'id': '26', 'type': 'list_comprehension', 'children': ['27', '28', '38']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '28', 'type': 'for_in_clause', 'children': ['29', '32']},{'id': '29', 'type': 'pattern_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '37', 'type': 'string', 'children': [], 'value': '"X_indices"'},{'id': '38', 'type': 'if_clause', 'children': ['39']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '45'], 'value': '=='},{'id': '40', 'type': 'subscript', 'children': ['41', '44']},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '43', 'type': 'string', 'children': [], 'value': '"X_meta"'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '45', 'type': 'string', 'children': [], 'value': '"c"'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'discrete'},{'id': '49', 'type': 'list_comprehension', 'children': ['50', '51', '61']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '51', 'type': 'for_in_clause', 'children': ['52', '55']},{'id': '52', 'type': 'pattern_list', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '60', 'type': 'string', 'children': [], 'value': '"X_indices"'},{'id': '61', 'type': 'if_clause', 'children': ['62']},{'id': '62', 'type': 'comparison_operator', 'children': ['63', '68'], 'value': '=='},{'id': '63', 'type': 'subscript', 'children': ['64', '67']},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '66', 'type': 'string', 'children': [], 'value': '"X_meta"'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '68', 'type': 'string', 'children': [], 'value': '"d"'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'cont'},{'id': '72', 'type': 'conditional_expression', 'children': ['73', '74', '80'], 'value': 'if'},{'id': '73', 'type': 'True', 'children': []},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '79'], 'value': '>'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'continuous'},{'id': '79', 'type': 'integer', 'children': [], 'value': '0'},{'id': '80', 'type': 'False', 'children': []},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'disc'},{'id': '84', 'type': 'conditional_expression', 'children': ['85', '86', '92'], 'value': 'if'},{'id': '85', 'type': 'True', 'children': []},{'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': 'discrete'},{'id': '91', 'type': 'integer', 'children': [], 'value': '0'},{'id': '92', 'type': 'False', 'children': []},{'id': '93', 'type': 'for_statement', 'children': ['94', '95', '96']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'inp'},{'id': '96', 'type': 'block', 'children': ['97', '112']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '100', 'type': 'call', 'children': ['101', '108']},{'id': '101', 'type': 'attribute', 'children': ['102', '107']},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '106', 'type': 'argument_list', 'children': []},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'subscript', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '111', 'type': 'string', 'children': [], 'value': '"delimiter"'},{'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': 'row'},{'id': '118', 'type': 'integer', 'children': [], 'value': '1'},{'id': '119', 'type': 'block', 'children': ['120', '136', '144', '216', '267', '286', '302', '319']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'x_id'},{'id': '123', 'type': 'conditional_expression', 'children': ['124', '125', '131'], 'value': 'if'},{'id': '124', 'type': 'string', 'children': [], 'value': '""'},{'id': '125', 'type': 'comparison_operator', 'children': ['126', '129'], 'value': '=='},{'id': '126', 'type': 'subscript', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '128', 'type': 'string', 'children': [], 'value': '"id_index"'},{'id': '129', 'type': 'unary_operator', 'children': ['130'], 'value': '-'},{'id': '130', 'type': 'integer', 'children': [], 'value': '1'},{'id': '131', 'type': 'subscript', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '135', 'type': 'string', 'children': [], 'value': '"id_index"'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'probs'},{'id': '139', 'type': 'subscript', 'children': ['140', '143']},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '142', 'type': 'string', 'children': [], 'value': '"fit_model"'},{'id': '143', 'type': 'string', 'children': [], 'value': '"prior_log"'},{'id': '144', 'type': 'if_statement', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'cont'},{'id': '146', 'type': 'block', 'children': ['147', '175']},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'x'},{'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': 'list_comprehension', 'children': ['156', '172']},{'id': '156', 'type': '()', 'children': ['157']},{'id': '157', 'type': 'conditional_expression', 'children': ['158', '159', '166'], 'value': 'if'},{'id': '158', 'type': 'integer', 'children': [], 'value': '0'},{'id': '159', 'type': 'comparison_operator', 'children': ['160', '163'], 'value': 'in'},{'id': '160', 'type': 'subscript', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '163', 'type': 'subscript', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '165', 'type': 'string', 'children': [], 'value': '"missing_vals"'},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '172', 'type': 'for_in_clause', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'continuous'},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'probs'},{'id': '178', 'type': 'binary_operator', 'children': ['179', '180'], 'value': '-'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'probs'},{'id': '180', 'type': 'binary_operator', 'children': ['181', '182'], 'value': '*'},{'id': '181', 'type': 'float', 'children': [], 'value': '0.5'},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '186', 'type': 'argument_list', 'children': ['187', '213']},{'id': '187', 'type': 'binary_operator', 'children': ['188', '208'], 'value': '+'},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'true_divide'},{'id': '192', 'type': 'argument_list', 'children': ['193', '203']},{'id': '193', 'type': 'binary_operator', 'children': ['194', '202'], 'value': '**'},{'id': '194', 'type': '()', 'children': ['195']},{'id': '195', 'type': 'binary_operator', 'children': ['196', '197'], 'value': '-'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '197', 'type': 'subscript', 'children': ['198', '201']},{'id': '198', 'type': 'subscript', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '200', 'type': 'string', 'children': [], 'value': '"fit_model"'},{'id': '201', 'type': 'string', 'children': [], 'value': '"mean"'},{'id': '202', 'type': 'integer', 'children': [], 'value': '2'},{'id': '203', 'type': 'subscript', 'children': ['204', '207']},{'id': '204', 'type': 'subscript', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '206', 'type': 'string', 'children': [], 'value': '"fit_model"'},{'id': '207', 'type': 'string', 'children': [], 'value': '"var"'},{'id': '208', 'type': 'subscript', 'children': ['209', '212']},{'id': '209', 'type': 'subscript', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '211', 'type': 'string', 'children': [], 'value': '"fit_model"'},{'id': '212', 'type': 'string', 'children': [], 'value': '"var_log"'},{'id': '213', 'type': 'keyword_argument', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '215', 'type': 'integer', 'children': [], 'value': '1'},{'id': '216', 'type': 'if_statement', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'disc'},{'id': '218', 'type': 'block', 'children': ['219']},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'probs'},{'id': '222', 'type': 'binary_operator', 'children': ['223', '224'], 'value': '+'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'probs'},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '228', 'type': 'argument_list', 'children': ['229', '264']},{'id': '229', 'type': 'list_comprehension', 'children': ['230', '261']},{'id': '230', 'type': '()', 'children': ['231']},{'id': '231', 'type': 'conditional_expression', 'children': ['232', '233', '240'], 'value': 'if'},{'id': '232', 'type': 'integer', 'children': [], 'value': '0'},{'id': '233', 'type': 'comparison_operator', 'children': ['234', '237'], 'value': 'in'},{'id': '234', 'type': 'subscript', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '237', 'type': 'subscript', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '239', 'type': 'string', 'children': [], 'value': '"missing_vals"'},{'id': '240', 'type': 'call', 'children': ['241', '246']},{'id': '241', 'type': 'attribute', 'children': ['242', '245']},{'id': '242', 'type': 'subscript', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '244', 'type': 'string', 'children': [], 'value': '"fit_model"'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '246', 'type': 'argument_list', 'children': ['247', '255']},{'id': '247', 'type': 'tuple', 'children': ['248', '252']},{'id': '248', 'type': 'call', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '252', 'type': 'subscript', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '255', 'type': 'call', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '259', 'type': 'argument_list', 'children': ['260']},{'id': '260', 'type': 'integer', 'children': [], 'value': '1'},{'id': '261', 'type': 'for_in_clause', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'discrete'},{'id': '264', 'type': 'keyword_argument', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '266', 'type': 'integer', 'children': [], 'value': '0'},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'assignment', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'log_prob_x'},{'id': '270', 'type': 'call', 'children': ['271', '274']},{'id': '271', 'type': 'attribute', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '274', 'type': 'argument_list', 'children': ['275']},{'id': '275', 'type': 'call', 'children': ['276', '279']},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '279', 'type': 'argument_list', 'children': ['280']},{'id': '280', 'type': 'call', 'children': ['281', '284']},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'exp'},{'id': '284', 'type': 'argument_list', 'children': ['285']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'probs'},{'id': '286', 'type': 'expression_statement', 'children': ['287']},{'id': '287', 'type': 'assignment', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'probs'},{'id': '289', 'type': 'call', 'children': ['290', '293']},{'id': '290', 'type': 'attribute', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'exp'},{'id': '293', 'type': 'argument_list', 'children': ['294']},{'id': '294', 'type': 'binary_operator', 'children': ['295', '301'], 'value': '-'},{'id': '295', 'type': 'call', 'children': ['296', '299']},{'id': '296', 'type': 'attribute', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '299', 'type': 'argument_list', 'children': ['300']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'probs'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'log_prob_x'},{'id': '302', 'type': 'expression_statement', 'children': ['303']},{'id': '303', 'type': 'assignment', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'y_predicted'},{'id': '305', 'type': 'subscript', 'children': ['306', '318']},{'id': '306', 'type': 'call', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '308', 'type': 'argument_list', 'children': ['309']},{'id': '309', 'type': 'call', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '311', 'type': 'argument_list', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'probs'},{'id': '313', 'type': 'subscript', 'children': ['314', '317']},{'id': '314', 'type': 'subscript', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '316', 'type': 'string', 'children': [], 'value': '"fit_model"'},{'id': '317', 'type': 'string', 'children': [], 'value': '"y_labels"'},{'id': '318', 'type': 'integer', 'children': [], 'value': '1'},{'id': '319', 'type': 'expression_statement', 'children': ['320']},{'id': '320', 'type': 'call', 'children': ['321', '324']},{'id': '321', 'type': 'attribute', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '324', 'type': 'argument_list', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'x_id'},{'id': '326', 'type': 'tuple', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'y_predicted'},{'id': '328', 'type': 'call', 'children': ['329', '332']},{'id': '329', 'type': 'attribute', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'probs'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'tolist'},{'id': '332', 'type': 'argument_list', 'children': []}
def map_predict(interface, state, label, inp): import numpy as np out = interface.output(0) continuous = [j for i, j in enumerate(state["X_indices"]) if state["X_meta"][i] == "c"] discrete = [j for i, j in enumerate(state["X_indices"]) if state["X_meta"][i] == "d"] cont = True if len(continuous) > 0 else False disc = True if len(discrete) > 0 else False for row in inp: row = row.strip().split(state["delimiter"]) if len(row) > 1: x_id = "" if state["id_index"] == -1 else row[state["id_index"]] probs = state["fit_model"]["prior_log"] if cont: x = np.array([(0 if row[j] in state["missing_vals"] else float(row[j])) for j in continuous]) probs = probs - 0.5 * np.sum( np.true_divide((x - state["fit_model"]["mean"]) ** 2, state["fit_model"]["var"]) + state["fit_model"]["var_log"], axis=1) if disc: probs = probs + np.sum( [(0 if row[i] in state["missing_vals"] else state["fit_model"].get((str(i), row[i]), np.zeros(1))) for i in discrete], axis=0) log_prob_x = np.log(np.sum(np.exp(probs))) probs = np.exp(np.array(probs) - log_prob_x) y_predicted = max(zip(probs, state["fit_model"]["y_labels"]))[1] out.add(x_id, (y_predicted, probs.tolist()))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'json_dumps'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '5', 'type': 'block', 'children': ['6', '28', '46', '55', '164']},{'id': '6', 'type': 'try_statement', 'children': ['7', '24']},{'id': '7', 'type': 'block', 'children': ['8']},{'id': '8', 'type': 'return_statement', 'children': ['9']},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '13', 'type': 'argument_list', 'children': ['14', '15', '18', '21']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '15', 'type': 'keyword_argument', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '17', 'type': 'integer', 'children': [], 'value': '2'},{'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '20', 'type': 'True', 'children': []},{'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'allow_nan'},{'id': '23', 'type': 'False', 'children': []},{'id': '24', 'type': 'except_clause', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'pass_statement', 'children': []},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'json_str'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37', '40', '43']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '39', 'type': 'integer', 'children': [], 'value': '2'},{'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '42', 'type': 'True', 'children': []},{'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'allow_nan'},{'id': '45', 'type': 'True', 'children': []},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'json_obj'},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'loads'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'json_str'},{'id': '55', 'type': 'function_definition', 'children': ['56', '57', '59']},{'id': '56', 'type': 'function_name', 'children': [], 'value': 'do_map'},{'id': '57', 'type': 'parameters', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '59', 'type': 'block', 'children': ['60', '67', '76', '108', '137', '147', '162']},{'id': '60', 'type': 'if_statement', 'children': ['61', '64']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'is'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '63', 'type': 'None', 'children': []},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'return_statement', 'children': ['66']},{'id': '66', 'type': 'None', 'children': []},{'id': '67', 'type': 'if_statement', 'children': ['68', '73']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '70', 'type': 'argument_list', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'return_statement', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '76', 'type': 'if_statement', 'children': ['77', '82']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '79', 'type': 'argument_list', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '82', 'type': 'block', 'children': ['83', '87', '106']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '86', 'type': 'dictionary', 'children': []},{'id': '87', 'type': 'for_statement', 'children': ['88', '91', '96']},{'id': '88', 'type': 'tuple_pattern', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '95', 'type': 'argument_list', 'children': []},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '102']},{'id': '99', 'type': 'subscript', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'do_map'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '106', 'type': 'return_statement', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '108', 'type': 'if_statement', 'children': ['109', '116']},{'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': 'obj'},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'Iterable'},{'id': '116', 'type': 'block', 'children': ['117', '121', '135']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '120', 'type': 'list', 'children': [], 'value': '[]'},{'id': '121', 'type': 'for_statement', 'children': ['122', '123', '124']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'do_map'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '135', 'type': 'return_statement', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '137', 'type': 'if_statement', 'children': ['138', '144']},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'math'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'isnan'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'return_statement', 'children': ['146']},{'id': '146', 'type': 'string', 'children': [], 'value': '"NaN"'},{'id': '147', 'type': 'if_statement', 'children': ['148', '154']},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'math'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'isinf'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'return_statement', 'children': ['156']},{'id': '156', 'type': 'conditional_expression', 'children': ['157', '158', '161'], 'value': 'if'},{'id': '157', 'type': 'string', 'children': [], 'value': '"Infinity"'},{'id': '158', 'type': 'comparison_operator', 'children': ['159', '160'], 'value': '>'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '160', 'type': 'integer', 'children': [], 'value': '0'},{'id': '161', 'type': 'string', 'children': [], 'value': '"-Infinity"'},{'id': '162', 'type': 'return_statement', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '164', 'type': 'return_statement', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '169', 'type': 'argument_list', 'children': ['170', '174', '177', '180']},{'id': '170', 'type': 'call', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'do_map'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'json_obj'},{'id': '174', 'type': 'keyword_argument', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '176', 'type': 'integer', 'children': [], 'value': '2'},{'id': '177', 'type': 'keyword_argument', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '179', 'type': 'True', 'children': []},{'id': '180', 'type': 'keyword_argument', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'allow_nan'},{'id': '182', 'type': 'False', 'children': []}
def json_dumps(obj): try: return json.dumps(obj, indent=2, sort_keys=True, allow_nan=False) except ValueError: pass json_str = json.dumps(obj, indent=2, sort_keys=True, allow_nan=True) json_obj = json.loads(json_str) def do_map(obj): if obj is None: return None if isinstance(obj, basestring): return obj if isinstance(obj, dict): res = {} for (key, value) in obj.items(): res[key] = do_map(value) return res if isinstance(obj, collections.Iterable): res = [] for el in obj: res.append(do_map(el)) return res if math.isnan(obj): return "NaN" if math.isinf(obj): return "Infinity" if obj > 0 else "-Infinity" return obj return json.dumps( do_map(json_obj), indent=2, sort_keys=True, allow_nan=False)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_json_mask'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'method_str'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'json_producer'},{'id': '8', 'type': 'block', 'children': ['9', '274']},{'id': '9', 'type': 'function_definition', 'children': ['10', '11', '14']},{'id': '10', 'type': 'function_name', 'children': [], 'value': 'send_json'},{'id': '11', 'type': 'parameters', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'drh'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'rem_path'},{'id': '14', 'type': 'block', 'children': ['15', '23', '38', '47', '53', '59', '74', '80', '87', '120', '127', '133', '141', '148', '243', '250', '258', '266', '272']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'json_producer'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'drh'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'rem_path'},{'id': '23', 'type': 'if_statement', 'children': ['24', '30']},{'id': '24', 'type': 'not_operator', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'Response'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'Response'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'ctype'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'get_ctype'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'string', 'children': [], 'value': '"application/json"'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '59', 'type': 'if_statement', 'children': ['60', '63']},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'is'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '62', 'type': 'None', 'children': []},{'id': '63', 'type': 'block', 'children': ['64', '72']},{'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': 'drh'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'send_error'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'integer', 'children': [], 'value': '404'},{'id': '71', 'type': 'string', 'children': [], 'value': '"File not found"'},{'id': '72', 'type': 'return_statement', 'children': ['73']},{'id': '73', 'type': 'None', 'children': []},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'BytesIO'},{'id': '79', 'type': 'argument_list', 'children': []},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'json_str'},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'json_dumps'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '87', 'type': 'if_statement', 'children': ['88', '95']},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'json_str'},{'id': '92', 'type': 'tuple', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'unicode'},{'id': '95', 'type': 'block', 'children': ['96', '111']},{'id': '96', 'type': 'try_statement', 'children': ['97', '107']},{'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': 'json_str'},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'json_str'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'string', 'children': [], 'value': "'utf8'"},{'id': '107', 'type': 'except_clause', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'pass_statement', 'children': []},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'json_str'},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'json_str'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'string', 'children': [], 'value': "'utf8'"},{'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': 'f'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'json_str'},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'flush'},{'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': 'size'},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'tell'},{'id': '140', 'type': 'argument_list', 'children': []},{'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': 'f'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'seek'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'integer', 'children': [], 'value': '0'},{'id': '148', 'type': 'if_statement', 'children': ['149', '154']},{'id': '149', 'type': 'comparison_operator', 'children': ['150', '153'], 'value': '>='},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'drh'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'request_version'},{'id': '153', 'type': 'string', 'children': [], 'value': '"HTTP/1.1"'},{'id': '154', 'type': 'block', 'children': ['155', '175', '182', '192', '214', '225']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'e_tag'},{'id': '158', 'type': 'call', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'string', 'children': [], 'value': '"{0:x}"'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'binary_operator', 'children': ['164', '174'], 'value': '&'},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'zlib'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'crc32'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '173', 'type': 'argument_list', 'children': []},{'id': '174', 'type': 'integer', 'children': [], 'value': '0xFFFFFFFF'},{'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': 'f'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'seek'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'integer', 'children': [], 'value': '0'},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': '_getheader'},{'id': '187', 'type': 'argument_list', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'drh'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '191', 'type': 'string', 'children': [], 'value': "'if-none-match'"},{'id': '192', 'type': 'if_statement', 'children': ['193', '196']},{'id': '193', 'type': 'comparison_operator', 'children': ['194', '195'], 'value': 'is'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '195', 'type': 'None', 'children': []},{'id': '196', 'type': 'block', 'children': ['197']},{'id': '197', 'type': 'if_statement', 'children': ['198', '205']},{'id': '198', 'type': 'call', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'drh'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'check_cache'},{'id': '202', 'type': 'argument_list', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'e_tag'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '205', 'type': 'block', 'children': ['206', '212']},{'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': 'f'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '211', 'type': 'argument_list', 'children': []},{'id': '212', 'type': 'return_statement', 'children': ['213']},{'id': '213', 'type': 'None', 'children': []},{'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': 'drh'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'send_header'},{'id': '219', 'type': 'argument_list', 'children': ['220', '221', '222']},{'id': '220', 'type': 'string', 'children': [], 'value': '"ETag"'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'e_tag'},{'id': '222', 'type': 'keyword_argument', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'end_header'},{'id': '224', 'type': 'True', 'children': []},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'call', 'children': ['227', '230']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'drh'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'send_header'},{'id': '230', 'type': 'argument_list', 'children': ['231', '232', '240']},{'id': '231', 'type': 'string', 'children': [], 'value': '"Cache-Control"'},{'id': '232', 'type': 'call', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'string', 'children': [], 'value': '"max-age={0}"'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'max_age'},{'id': '240', 'type': 'keyword_argument', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'end_header'},{'id': '242', 'type': 'True', 'children': []},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'call', 'children': ['245', '248']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'drh'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'send_response'},{'id': '248', 'type': 'argument_list', 'children': ['249']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'code'},{'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': 'drh'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'send_header'},{'id': '255', 'type': 'argument_list', 'children': ['256', '257']},{'id': '256', 'type': 'string', 'children': [], 'value': '"Content-Type"'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'ctype'},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'call', 'children': ['260', '263']},{'id': '260', 'type': 'attribute', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'drh'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'send_header'},{'id': '263', 'type': 'argument_list', 'children': ['264', '265']},{'id': '264', 'type': 'string', 'children': [], 'value': '"Content-Length"'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'call', 'children': ['268', '271']},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'drh'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'end_headers'},{'id': '271', 'type': 'argument_list', 'children': []},{'id': '272', 'type': 'return_statement', 'children': ['273']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'call', 'children': ['276', '279']},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '278', 'type': 'identifier', 'children': [], 'value': '_add_file_mask'},{'id': '279', 'type': 'argument_list', 'children': ['280', '281', '282']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'method_str'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'send_json'}
def add_json_mask(self, start, method_str, json_producer): def send_json(drh, rem_path): obj = json_producer(drh, rem_path) if not isinstance(obj, Response): obj = Response(obj) ctype = obj.get_ctype("application/json") code = obj.code obj = obj.response if obj is None: drh.send_error(404, "File not found") return None f = BytesIO() json_str = json_dumps(obj) if isinstance(json_str, (str, unicode)): try: json_str = json_str.decode('utf8') except AttributeError: pass json_str = json_str.encode('utf8') f.write(json_str) f.flush() size = f.tell() f.seek(0) if drh.request_version >= "HTTP/1.1": e_tag = "{0:x}".format(zlib.crc32(f.read()) & 0xFFFFFFFF) f.seek(0) match = _getheader(drh.headers, 'if-none-match') if match is not None: if drh.check_cache(e_tag, match): f.close() return None drh.send_header("ETag", e_tag, end_header=True) drh.send_header("Cache-Control", "max-age={0}".format(self.max_age), end_header=True) drh.send_response(code) drh.send_header("Content-Type", ctype) drh.send_header("Content-Length", size) drh.end_headers() return f self._add_file_mask(start, method_str, send_json)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_text_mask'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'method_str'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'text_producer'},{'id': '8', 'type': 'block', 'children': ['9', '267']},{'id': '9', 'type': 'function_definition', 'children': ['10', '11', '14']},{'id': '10', 'type': 'function_name', 'children': [], 'value': 'send_text'},{'id': '11', 'type': 'parameters', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'drh'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'rem_path'},{'id': '14', 'type': 'block', 'children': ['15', '23', '38', '47', '53', '59', '74', '80', '113', '120', '126', '134', '141', '236', '243', '251', '259', '265']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'text_producer'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'drh'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'rem_path'},{'id': '23', 'type': 'if_statement', 'children': ['24', '30']},{'id': '24', 'type': 'not_operator', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'Response'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'Response'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'ctype'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'get_ctype'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'string', 'children': [], 'value': '"text/plain"'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '59', 'type': 'if_statement', 'children': ['60', '63']},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'is'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '62', 'type': 'None', 'children': []},{'id': '63', 'type': 'block', 'children': ['64', '72']},{'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': 'drh'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'send_error'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'integer', 'children': [], 'value': '404'},{'id': '71', 'type': 'string', 'children': [], 'value': '"File not found"'},{'id': '72', 'type': 'return_statement', 'children': ['73']},{'id': '73', 'type': 'None', 'children': []},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'BytesIO'},{'id': '79', 'type': 'argument_list', 'children': []},{'id': '80', 'type': 'if_statement', 'children': ['81', '88']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '83', 'type': 'argument_list', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '85', 'type': 'tuple', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'unicode'},{'id': '88', 'type': 'block', 'children': ['89', '104']},{'id': '89', 'type': 'try_statement', 'children': ['90', '100']},{'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': 'text'},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'string', 'children': [], 'value': "'utf8'"},{'id': '100', 'type': 'except_clause', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'pass_statement', 'children': []},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'string', 'children': [], 'value': "'utf8'"},{'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': 'f'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'text'},{'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': 'f'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '125', 'type': 'argument_list', 'children': []},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'tell'},{'id': '133', 'type': 'argument_list', 'children': []},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'seek'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'integer', 'children': [], 'value': '0'},{'id': '141', 'type': 'if_statement', 'children': ['142', '147']},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '146'], 'value': '>='},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'drh'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'request_version'},{'id': '146', 'type': 'string', 'children': [], 'value': '"HTTP/1.1"'},{'id': '147', 'type': 'block', 'children': ['148', '168', '175', '185', '207', '218']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'e_tag'},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'string', 'children': [], 'value': '"{0:x}"'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'binary_operator', 'children': ['157', '167'], 'value': '&'},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'zlib'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'crc32'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '166', 'type': 'argument_list', 'children': []},{'id': '167', 'type': 'integer', 'children': [], 'value': '0xFFFFFFFF'},{'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': 'f'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'seek'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'integer', 'children': [], 'value': '0'},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': '_getheader'},{'id': '180', 'type': 'argument_list', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'drh'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '184', 'type': 'string', 'children': [], 'value': "'if-none-match'"},{'id': '185', 'type': 'if_statement', 'children': ['186', '189']},{'id': '186', 'type': 'comparison_operator', 'children': ['187', '188'], 'value': 'is'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '188', 'type': 'None', 'children': []},{'id': '189', 'type': 'block', 'children': ['190']},{'id': '190', 'type': 'if_statement', 'children': ['191', '198']},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'drh'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'check_cache'},{'id': '195', 'type': 'argument_list', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'e_tag'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '198', 'type': 'block', 'children': ['199', '205']},{'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': 'f'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '204', 'type': 'argument_list', 'children': []},{'id': '205', 'type': 'return_statement', 'children': ['206']},{'id': '206', 'type': 'None', 'children': []},{'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': 'drh'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'send_header'},{'id': '212', 'type': 'argument_list', 'children': ['213', '214', '215']},{'id': '213', 'type': 'string', 'children': [], 'value': '"ETag"'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'e_tag'},{'id': '215', 'type': 'keyword_argument', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'end_header'},{'id': '217', 'type': 'True', 'children': []},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'drh'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'send_header'},{'id': '223', 'type': 'argument_list', 'children': ['224', '225', '233']},{'id': '224', 'type': 'string', 'children': [], 'value': '"Cache-Control"'},{'id': '225', 'type': 'call', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'string', 'children': [], 'value': '"max-age={0}"'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '229', 'type': 'argument_list', 'children': ['230']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'max_age'},{'id': '233', 'type': 'keyword_argument', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'end_header'},{'id': '235', 'type': 'True', 'children': []},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'call', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'drh'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'send_response'},{'id': '241', 'type': 'argument_list', 'children': ['242']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'call', 'children': ['245', '248']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'drh'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'send_header'},{'id': '248', 'type': 'argument_list', 'children': ['249', '250']},{'id': '249', 'type': 'string', 'children': [], 'value': '"Content-Type"'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'ctype'},{'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': 'drh'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'send_header'},{'id': '256', 'type': 'argument_list', 'children': ['257', '258']},{'id': '257', 'type': 'string', 'children': [], 'value': '"Content-Length"'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'size'},{'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': 'drh'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'end_headers'},{'id': '264', 'type': 'argument_list', 'children': []},{'id': '265', 'type': 'return_statement', 'children': ['266']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'f'},{'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': 'self'},{'id': '271', 'type': 'identifier', 'children': [], 'value': '_add_file_mask'},{'id': '272', 'type': 'argument_list', 'children': ['273', '274', '275']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'method_str'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'send_text'}
def add_text_mask(self, start, method_str, text_producer): def send_text(drh, rem_path): text = text_producer(drh, rem_path) if not isinstance(text, Response): text = Response(text) ctype = text.get_ctype("text/plain") code = text.code text = text.response if text is None: drh.send_error(404, "File not found") return None f = BytesIO() if isinstance(text, (str, unicode)): try: text = text.decode('utf8') except AttributeError: pass text = text.encode('utf8') f.write(text) f.flush() size = f.tell() f.seek(0) if drh.request_version >= "HTTP/1.1": e_tag = "{0:x}".format(zlib.crc32(f.read()) & 0xFFFFFFFF) f.seek(0) match = _getheader(drh.headers, 'if-none-match') if match is not None: if drh.check_cache(e_tag, match): f.close() return None drh.send_header("ETag", e_tag, end_header=True) drh.send_header("Cache-Control", "max-age={0}".format(self.max_age), end_header=True) drh.send_response(code) drh.send_header("Content-Type", ctype) drh.send_header("Content-Length", size) drh.end_headers() return f self._add_file_mask(start, method_str, send_text)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_token_obj'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'expire'},{'id': '8', 'type': 'identifier', 'children': [], 'value': '_token_default'},{'id': '9', 'type': 'block', 'children': ['10', '23', '29', '40']},{'id': '10', 'type': 'if_statement', 'children': ['11', '14']},{'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': '=='},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'expire'},{'id': '13', 'type': 'identifier', 'children': [], 'value': '_token_default'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'expire'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'get_default_token_expiration'},{'id': '22', 'type': 'argument_list', 'children': []},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'get_time'},{'id': '28', 'type': 'argument_list', 'children': []},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'until'},{'id': '32', 'type': 'conditional_expression', 'children': ['33', '36', '39'], 'value': 'if'},{'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '+'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'expire'},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'is'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'expire'},{'id': '38', 'type': 'None', 'children': []},{'id': '39', 'type': 'None', 'children': []},{'id': '40', 'type': 'with_statement', 'children': ['41', '46']},{'id': '41', 'type': 'with_clause', 'children': ['42']},{'id': '42', 'type': 'with_item', 'children': ['43']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': '_token_lock'},{'id': '46', 'type': 'block', 'children': ['47', '51', '86', '133']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'first_valid'},{'id': '50', 'type': 'None', 'children': []},{'id': '51', 'type': 'for_statement', 'children': ['52', '55', '61']},{'id': '52', 'type': 'tuple_pattern', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': '_token_timings'},{'id': '61', 'type': 'block', 'children': ['62', '72']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 't'},{'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': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': '_token_map'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '71', 'type': 'integer', 'children': [], 'value': '0'},{'id': '72', 'type': 'if_statement', 'children': ['73', '80']},{'id': '73', 'type': 'boolean_operator', 'children': ['74', '77'], 'value': 'or'},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '76'], 'value': 'is'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '76', 'type': 'None', 'children': []},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': '>'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '80', 'type': 'block', 'children': ['81', '85']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'first_valid'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '85', 'type': 'break_statement', 'children': []},{'id': '86', 'type': 'if_statement', 'children': ['87', '90', '103']},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': 'is'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'first_valid'},{'id': '89', 'type': 'None', 'children': []},{'id': '90', 'type': 'block', 'children': ['91', '97']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '95', 'type': 'identifier', 'children': [], 'value': '_token_map'},{'id': '96', 'type': 'dictionary', 'children': []},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '101', 'type': 'identifier', 'children': [], 'value': '_token_timings'},{'id': '102', 'type': 'list', 'children': [], 'value': '[]'},{'id': '103', 'type': 'else_clause', 'children': ['104']},{'id': '104', 'type': 'block', 'children': ['105', '121']},{'id': '105', 'type': 'for_statement', 'children': ['106', '107', '114']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '107', 'type': 'subscript', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '110', 'type': 'identifier', 'children': [], 'value': '_token_timings'},{'id': '111', 'type': 'slice', 'children': ['112', '113']},{'id': '112', 'type': 'colon', 'children': []},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'first_valid'},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'delete_statement', 'children': ['116']},{'id': '116', 'type': 'subscript', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '119', 'type': 'identifier', 'children': [], 'value': '_token_map'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '125', 'type': 'identifier', 'children': [], 'value': '_token_timings'},{'id': '126', 'type': 'subscript', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '129', 'type': 'identifier', 'children': [], 'value': '_token_timings'},{'id': '130', 'type': 'slice', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'first_valid'},{'id': '132', 'type': 'colon', 'children': []},{'id': '133', 'type': 'if_statement', 'children': ['134', '141', '227']},{'id': '134', 'type': 'boolean_operator', 'children': ['135', '138'], 'value': 'or'},{'id': '135', 'type': 'comparison_operator', 'children': ['136', '137'], 'value': 'is'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'until'},{'id': '137', 'type': 'None', 'children': []},{'id': '138', 'type': 'comparison_operator', 'children': ['139', '140'], 'value': '>'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'until'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '141', 'type': 'block', 'children': ['142', '186', '219']},{'id': '142', 'type': 'if_statement', 'children': ['143', '148', '168']},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '145'], 'value': 'not'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '147', 'type': 'identifier', 'children': [], 'value': '_token_map'},{'id': '148', 'type': 'block', 'children': ['149', '159']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '156']},{'id': '151', 'type': 'subscript', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '154', 'type': 'identifier', 'children': [], 'value': '_token_map'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '156', 'type': 'tuple', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'until'},{'id': '158', 'type': 'dictionary', 'children': []},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'call', 'children': ['161', '166']},{'id': '161', 'type': 'attribute', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '164', 'type': 'identifier', 'children': [], 'value': '_token_timings'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '168', 'type': 'else_clause', 'children': ['169']},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '177']},{'id': '172', 'type': 'subscript', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '175', 'type': 'identifier', 'children': [], 'value': '_token_map'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '177', 'type': 'tuple', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'until'},{'id': '179', 'type': 'subscript', 'children': ['180', '185']},{'id': '180', 'type': 'subscript', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '183', 'type': 'identifier', 'children': [], 'value': '_token_map'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '185', 'type': 'integer', 'children': [], 'value': '1'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'call', 'children': ['188', '193']},{'id': '188', 'type': 'attribute', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '191', 'type': 'identifier', 'children': [], 'value': '_token_timings'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'keyword_argument', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '196', 'type': 'lambda', 'children': ['197', '199']},{'id': '197', 'type': 'lambda_parameters', 'children': ['198']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '199', 'type': 'tuple', 'children': ['200', '212']},{'id': '200', 'type': 'conditional_expression', 'children': ['201', '202', '211'], 'value': 'if'},{'id': '201', 'type': 'integer', 'children': [], 'value': '1'},{'id': '202', 'type': 'comparison_operator', 'children': ['203', '210'], 'value': 'is'},{'id': '203', 'type': 'subscript', 'children': ['204', '209']},{'id': '204', 'type': 'subscript', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '207', 'type': 'identifier', 'children': [], 'value': '_token_map'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '209', 'type': 'integer', 'children': [], 'value': '0'},{'id': '210', 'type': 'None', 'children': []},{'id': '211', 'type': 'integer', 'children': [], 'value': '0'},{'id': '212', 'type': 'subscript', 'children': ['213', '218']},{'id': '213', 'type': 'subscript', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '216', 'type': 'identifier', 'children': [], 'value': '_token_map'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '218', 'type': 'integer', 'children': [], 'value': '0'},{'id': '219', 'type': 'return_statement', 'children': ['220']},{'id': '220', 'type': 'subscript', 'children': ['221', '226']},{'id': '221', 'type': 'subscript', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '224', 'type': 'identifier', 'children': [], 'value': '_token_map'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '226', 'type': 'integer', 'children': [], 'value': '1'},{'id': '227', 'type': 'else_clause', 'children': ['228']},{'id': '228', 'type': 'block', 'children': ['229', '258']},{'id': '229', 'type': 'if_statement', 'children': ['230', '235']},{'id': '230', 'type': 'comparison_operator', 'children': ['231', '232'], 'value': 'in'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '234', 'type': 'identifier', 'children': [], 'value': '_token_map'},{'id': '235', 'type': 'block', 'children': ['236', '252']},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'assignment', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '240', 'type': 'identifier', 'children': [], 'value': '_token_timings'},{'id': '241', 'type': 'list_comprehension', 'children': ['242', '243', '248']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '243', 'type': 'for_in_clause', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '247', 'type': 'identifier', 'children': [], 'value': '_token_timings'},{'id': '248', 'type': 'if_clause', 'children': ['249']},{'id': '249', 'type': 'comparison_operator', 'children': ['250', '251'], 'value': '!='},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '252', 'type': 'delete_statement', 'children': ['253']},{'id': '253', 'type': 'subscript', 'children': ['254', '257']},{'id': '254', 'type': 'attribute', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '256', 'type': 'identifier', 'children': [], 'value': '_token_map'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '258', 'type': 'return_statement', 'children': ['259']},{'id': '259', 'type': 'dictionary', 'children': []}
def get_token_obj(self, token, expire=_token_default): if expire == _token_default: expire = self.get_default_token_expiration() now = get_time() until = now + expire if expire is not None else None with self._token_lock: first_valid = None for (pos, k) in enumerate(self._token_timings): t = self._token_map[k][0] if t is None or t > now: first_valid = pos break if first_valid is None: self._token_map = {} self._token_timings = [] else: for k in self._token_timings[:first_valid]: del self._token_map[k] self._token_timings = self._token_timings[first_valid:] if until is None or until > now: if token not in self._token_map: self._token_map[token] = (until, {}) self._token_timings.append(token) else: self._token_map[token] = (until, self._token_map[token][1]) self._token_timings.sort(key=lambda k: ( 1 if self._token_map[k][0] is None else 0, self._token_map[k][0] )) return self._token_map[token][1] else: if token in self._token_map: self._token_timings = [ k for k in self._token_timings if k != token ] del self._token_map[token] return {}
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'handle_cmd'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '6', 'type': 'block', 'children': ['7', '15', '19', '121', '132', '154', '161', '213']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '14', 'type': 'argument_list', 'children': []},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'segments'},{'id': '18', 'type': 'list', 'children': [], 'value': '[]'},{'id': '19', 'type': 'for_statement', 'children': ['20', '21', '26']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '25', 'type': 'argument_list', 'children': []},{'id': '26', 'type': 'block', 'children': ['27', '109']},{'id': '27', 'type': 'if_statement', 'children': ['28', '31', '61']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '31', 'type': 'ERROR', 'children': ['32', '40', '41', '42', '50', '56']},{'id': '32', 'type': 'ERROR', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'break'},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'segments'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '41', 'type': 'list', 'children': [], 'value': '[]'},{'id': '42', 'type': 'ERROR', 'children': ['43', '48', '49']},{'id': '43', 'type': 'not_operator', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'segments'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'segments'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'cur_cmd'},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'string', 'children': [], 'value': '"_"'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'segments'},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'in'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'cur_cmd'},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': '_cmd_methods'},{'id': '61', 'type': 'block', 'children': ['62', '70', '99', '108']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'argc'},{'id': '65', 'type': 'subscript', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': '_cmd_argc'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'cur_cmd'},{'id': '70', 'type': 'if_statement', 'children': ['71', '81']},{'id': '71', 'type': 'boolean_operator', 'children': ['72', '75'], 'value': 'and'},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': 'is'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'argc'},{'id': '74', 'type': 'None', 'children': []},{'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': 'args'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'argc'},{'id': '81', 'type': 'block', 'children': ['82', '98']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '85', 'type': 'argument_list', 'children': ['86', '87', '93', '94']},{'id': '86', 'type': 'string', 'children': [], 'value': "'command {0} expects {1} argument(s), got {2}'"},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'string', 'children': [], 'value': '" "'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'segments'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'argc'},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '98', 'type': 'return_statement', 'children': []},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '106']},{'id': '101', 'type': 'subscript', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '104', 'type': 'identifier', 'children': [], 'value': '_cmd_methods'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'cur_cmd'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '108', 'type': 'return_statement', 'children': []},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '114', 'type': 'argument_list', 'children': ['115', '116']},{'id': '115', 'type': 'integer', 'children': [], 'value': '0'},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'segments'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '120', 'type': 'argument_list', 'children': []},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '124', 'type': 'binary_operator', 'children': ['125', '131'], 'value': '+'},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '131', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '137', 'type': 'argument_list', 'children': ['138', '147']},{'id': '138', 'type': 'lambda', 'children': ['139', '141']},{'id': '139', 'type': 'lambda_parameters', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '147', 'type': 'call', 'children': ['148', '153']},{'id': '148', 'type': 'attribute', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '151', 'type': 'identifier', 'children': [], 'value': '_cmd_methods'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '153', 'type': 'argument_list', 'children': []},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'candidates'},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'list', 'children': [], 'value': '[]'},{'id': '161', 'type': 'for_statement', 'children': ['162', '163', '164']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '164', 'type': 'block', 'children': ['165', '177', '188', '206']},{'id': '165', 'type': 'if_statement', 'children': ['166', '175']},{'id': '166', 'type': 'comparison_operator', 'children': ['167', '171'], 'value': '<='},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '175', 'type': 'block', 'children': ['176']},{'id': '176', 'type': 'continue_statement', 'children': []},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '180', 'type': 'subscript', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '182', 'type': 'slice', 'children': ['183', '187']},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '187', 'type': 'colon', 'children': []},{'id': '188', 'type': 'if_statement', 'children': ['189', '192']},{'id': '189', 'type': 'comparison_operator', 'children': ['190', '191'], 'value': 'in'},{'id': '190', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '192', 'type': 'block', 'children': ['193']},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '196', 'type': 'subscript', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '198', 'type': 'slice', 'children': ['199', '200']},{'id': '199', 'type': 'colon', 'children': []},{'id': '200', 'type': 'call', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'string', 'children': [], 'value': "'_'"},{'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': 'candidates'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '213', 'type': 'if_statement', 'children': ['214', '218', '240']},{'id': '214', 'type': 'call', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'candidates'},{'id': '218', 'type': 'block', 'children': ['219', '230']},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'call', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '222', 'type': 'argument_list', 'children': ['223', '224']},{'id': '223', 'type': 'string', 'children': [], 'value': '\'command "{0}" needs more arguments:\''},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'string', 'children': [], 'value': "' '"},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '230', 'type': 'for_statement', 'children': ['231', '232', '233']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'candidates'},{'id': '233', 'type': 'block', 'children': ['234']},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'call', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '237', 'type': 'argument_list', 'children': ['238', '239']},{'id': '238', 'type': 'string', 'children': [], 'value': "' {0}'"},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '240', 'type': 'else_clause', 'children': ['241']},{'id': '241', 'type': 'block', 'children': ['242']},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'call', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '245', 'type': 'argument_list', 'children': ['246', '249']},{'id': '246', 'type': 'binary_operator', 'children': ['247', '248'], 'value': '+'},{'id': '247', 'type': 'string', 'children': [], 'value': '\'command "{0}" invalid; type \''},{'id': '248', 'type': 'string', 'children': [], 'value': "'help or use <TAB> for a list of commands'"},{'id': '249', 'type': 'call', 'children': ['250', '253']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'string', 'children': [], 'value': "' '"},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'args'}
def handle_cmd(self, cmd): cmd = cmd.strip() segments = [] for s in cmd.split(): if s.startswith(' break segments.append(s) args = [] if not len(segments): return while segments: cur_cmd = "_".join(segments) if cur_cmd in self._cmd_methods: argc = self._cmd_argc[cur_cmd] if argc is not None and len(args) != argc: msg('command {0} expects {1} argument(s), got {2}', " ".join(segments), argc, len(args)) return self._cmd_methods[cur_cmd](args) return args.insert(0, segments.pop()) prefix = '_'.join(args) + '_' matches = filter( lambda cmd: cmd.startswith(prefix), self._cmd_methods.keys()) candidates = set([]) for m in matches: if len(m) <= len(prefix): continue m = m[len(prefix):] if '_' in m: m = m[:m.index('_')] candidates.add(m) if len(candidates): msg('command "{0}" needs more arguments:', ' '.join(args)) for c in candidates: msg(' {0}', c) else: msg('command "{0}" invalid; type ' + 'help or use <TAB> for a list of commands', ' '.join(args))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'handle_request'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '16', '44', '50', '54', '60', '79', '172']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '9', 'type': 'call', 'children': ['10', '15']},{'id': '10', 'type': 'attribute', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'socket'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'gettimeout'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'if_statement', 'children': ['17', '20', '27']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '27', 'type': 'elif_clause', 'children': ['28', '33']},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '32'], 'value': 'is'},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '32', 'type': 'None', 'children': []},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'ctime'},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'get_time'},{'id': '49', 'type': 'argument_list', 'children': []},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'done_req'},{'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': 'shutdown_latency'},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'shutdown_latency'},{'id': '60', 'type': 'if_statement', 'children': ['61', '64']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'is'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '63', 'type': 'None', 'children': []},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'shutdown_latency'},{'id': '68', 'type': 'conditional_expression', 'children': ['69', '74', '75', '78'], 'value': 'if'},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '71', 'type': 'argument_list', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'shutdown_latency'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '74', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'is'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'shutdown_latency'},{'id': '77', 'type': 'None', 'children': []},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '79', 'type': 'while_statement', 'children': ['80', '105']},{'id': '80', 'type': 'boolean_operator', 'children': ['81', '88'], 'value': 'and'},{'id': '81', 'type': 'not_operator', 'children': ['82']},{'id': '82', 'type': '()', 'children': ['83']},{'id': '83', 'type': 'boolean_operator', 'children': ['84', '87'], 'value': 'or'},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'done'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'done_req'},{'id': '88', 'type': '()', 'children': ['89']},{'id': '89', 'type': 'boolean_operator', 'children': ['90', '97'], 'value': 'or'},{'id': '90', 'type': 'boolean_operator', 'children': ['91', '94'], 'value': 'or'},{'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': 'is'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '93', 'type': 'None', 'children': []},{'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': '=='},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '96', 'type': 'integer', 'children': [], 'value': '0'},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '104'], 'value': '<'},{'id': '98', 'type': '()', 'children': ['99']},{'id': '99', 'type': 'binary_operator', 'children': ['100', '103'], 'value': '-'},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'get_time'},{'id': '102', 'type': 'argument_list', 'children': []},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'ctime'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '105', 'type': 'block', 'children': ['106', '150', '166']},{'id': '106', 'type': 'try_statement', 'children': ['107', '121']},{'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': 'fd_sets'},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '115', 'type': 'argument_list', 'children': ['116', '118', '119', '120']},{'id': '116', 'type': 'list', 'children': ['117'], 'value': '[self]'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '118', 'type': 'list', 'children': [], 'value': '[]'},{'id': '119', 'type': 'list', 'children': [], 'value': '[]'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'shutdown_latency'},{'id': '121', 'type': 'except_clause', 'children': ['122', '130']},{'id': '122', 'type': 'as_pattern', 'children': ['123', '128']},{'id': '123', 'type': 'tuple', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'OSError'},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '128', 'type': 'as_pattern_target', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '130', 'type': 'block', 'children': ['131', '143']},{'id': '131', 'type': 'if_statement', 'children': ['132', '141']},{'id': '132', 'type': 'comparison_operator', 'children': ['133', '138'], 'value': '!='},{'id': '133', 'type': 'subscript', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '137', 'type': 'integer', 'children': [], 'value': '0'},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'errno'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'EINTR'},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'raise_statement', 'children': []},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'fd_sets'},{'id': '146', 'type': 'list', 'children': ['147', '148', '149'], 'value': '[[], [], []]'},{'id': '147', 'type': 'list', 'children': [], 'value': '[]'},{'id': '148', 'type': 'list', 'children': [], 'value': '[]'},{'id': '149', 'type': 'list', 'children': [], 'value': '[]'},{'id': '150', 'type': 'for_statement', 'children': ['151', '152', '155']},{'id': '151', 'type': 'identifier', 'children': [], 'value': '_fd'},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'fd_sets'},{'id': '154', 'type': 'integer', 'children': [], 'value': '0'},{'id': '155', 'type': 'block', 'children': ['156', '160']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'done_req'},{'id': '159', 'type': 'True', 'children': []},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '164', 'type': 'identifier', 'children': [], 'value': '_handle_request_noblock'},{'id': '165', 'type': 'argument_list', 'children': []},{'id': '166', 'type': 'if_statement', 'children': ['167', '170']},{'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': '=='},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '169', 'type': 'integer', 'children': [], 'value': '0'},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'break_statement', 'children': []},{'id': '172', 'type': 'if_statement', 'children': ['173', '180']},{'id': '173', 'type': 'not_operator', 'children': ['174']},{'id': '174', 'type': '()', 'children': ['175']},{'id': '175', 'type': 'boolean_operator', 'children': ['176', '179'], 'value': 'or'},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'done'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'done_req'},{'id': '180', 'type': 'block', 'children': ['181']},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'handle_timeout'},{'id': '186', 'type': 'argument_list', 'children': []}
def handle_request(self): timeout = self.socket.gettimeout() if timeout is None: timeout = self.timeout elif self.timeout is not None: timeout = min(timeout, self.timeout) ctime = get_time() done_req = False shutdown_latency = self.shutdown_latency if timeout is not None: shutdown_latency = min(shutdown_latency, timeout) \ if shutdown_latency is not None else timeout while not (self.done or done_req) and (timeout is None or timeout == 0 or (get_time() - ctime) < timeout): try: fd_sets = select.select([self], [], [], shutdown_latency) except (OSError, select.error) as e: if e.args[0] != errno.EINTR: raise fd_sets = [[], [], []] for _fd in fd_sets[0]: done_req = True self._handle_request_noblock() if timeout == 0: break if not (self.done or done_req): self.handle_timeout()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'info_gain_nominal'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'separate_max'},{'id': '7', 'type': 'block', 'children': ['8', '17', '27', '34', '45', '58', '96', '105', '115', '311']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'x_vals'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '17', 'type': 'if_statement', 'children': ['18', '24']},{'id': '18', 'type': 'comparison_operator', 'children': ['19', '23'], 'value': '<'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'x_vals'},{'id': '23', 'type': 'integer', 'children': [], 'value': '3'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'return_statement', 'children': ['26']},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'y_dist'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'Counter'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'h_y'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'y_dist'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '50']},{'id': '47', 'type': 'pattern_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'dist'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'splits'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'nominal_splits'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54', '55', '56', '57']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'x_vals'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'y_dist'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'separate_max'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '63']},{'id': '60', 'type': 'pattern_list', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'repeat'},{'id': '63', 'type': 'conditional_expression', 'children': ['64', '74', '80'], 'value': 'if'},{'id': '64', 'type': 'tuple', 'children': ['65', '73']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '67', 'type': 'argument_list', 'children': ['68', '69']},{'id': '68', 'type': 'integer', 'children': [], 'value': '1'},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'dist'},{'id': '73', 'type': 'integer', 'children': [], 'value': '1'},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '79'], 'value': '<'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'dist'},{'id': '79', 'type': 'integer', 'children': [], 'value': '50'},{'id': '80', 'type': 'tuple', 'children': ['81', '95']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '83', 'type': 'argument_list', 'children': ['84', '85', '89']},{'id': '84', 'type': 'integer', 'children': [], 'value': '1'},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'dist'},{'id': '89', 'type': 'binary_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': 'dist'},{'id': '94', 'type': 'integer', 'children': [], 'value': '10'},{'id': '95', 'type': 'integer', 'children': [], 'value': '3'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '99', 'type': 'binary_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': 'dist'},{'id': '104', 'type': 'integer', 'children': [], 'value': '10'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '111']},{'id': '107', 'type': 'pattern_list', 'children': ['108', '109', '110']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'max_ig'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'max_i'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'iteration'},{'id': '111', 'type': 'expression_list', 'children': ['112', '113', '114']},{'id': '112', 'type': 'integer', 'children': [], 'value': '0'},{'id': '113', 'type': 'integer', 'children': [], 'value': '1'},{'id': '114', 'type': 'integer', 'children': [], 'value': '0'},{'id': '115', 'type': 'while_statement', 'children': ['116', '119']},{'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': '<'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'iteration'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'repeat'},{'id': '119', 'type': 'block', 'children': ['120', '232', '236']},{'id': '120', 'type': 'for_statement', 'children': ['121', '122', '123']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '123', 'type': 'block', 'children': ['124', '141', '158', '191', '219']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'dist0'},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'list_comprehension', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '134', 'type': 'for_in_clause', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '136', 'type': 'subscript', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'dist'},{'id': '138', 'type': 'slice', 'children': ['139', '140']},{'id': '139', 'type': 'colon', 'children': []},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'dist1'},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'list_comprehension', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '151', 'type': 'for_in_clause', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '153', 'type': 'subscript', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'dist'},{'id': '155', 'type': 'slice', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '157', 'type': 'colon', 'children': []},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'coef'},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'true_divide'},{'id': '165', 'type': 'argument_list', 'children': ['166', '187']},{'id': '166', 'type': 'list', 'children': ['167', '177'], 'value': '[np.sum(dist0.values()), np.sum(dist1.values())]'},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'dist0'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '176', 'type': 'argument_list', 'children': []},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'dist1'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '186', 'type': 'argument_list', 'children': []},{'id': '187', 'type': 'call', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'ig'},{'id': '194', 'type': 'binary_operator', 'children': ['195', '196'], 'value': '-'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'h_y'},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'dot'},{'id': '200', 'type': 'argument_list', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'coef'},{'id': '202', 'type': 'list', 'children': ['203', '211'], 'value': '[h(dist0.values()), h(dist1.values())]'},{'id': '203', 'type': 'call', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'call', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'dist0'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '210', 'type': 'argument_list', 'children': []},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'dist1'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '218', 'type': 'argument_list', 'children': []},{'id': '219', 'type': 'if_statement', 'children': ['220', '223']},{'id': '220', 'type': 'comparison_operator', 'children': ['221', '222'], 'value': '>'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'ig'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'max_ig'},{'id': '223', 'type': 'block', 'children': ['224']},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '229']},{'id': '226', 'type': 'pattern_list', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'max_ig'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'max_i'},{'id': '229', 'type': 'expression_list', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'ig'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'augmented_assignment', 'children': ['234', '235'], 'value': '+='},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'iteration'},{'id': '235', 'type': 'integer', 'children': [], 'value': '1'},{'id': '236', 'type': 'if_statement', 'children': ['237', '240']},{'id': '237', 'type': 'comparison_operator', 'children': ['238', '239'], 'value': '>'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'repeat'},{'id': '239', 'type': 'integer', 'children': [], 'value': '1'},{'id': '240', 'type': 'block', 'children': ['241', '250', '271', '282', '298']},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'assignment', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '244', 'type': 'call', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'binary_operator', 'children': ['248', '249'], 'value': '*'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '249', 'type': 'float', 'children': [], 'value': '0.5'},{'id': '250', 'type': 'if_statement', 'children': ['251', '258', '268']},{'id': '251', 'type': 'boolean_operator', 'children': ['252', '255'], 'value': 'and'},{'id': '252', 'type': 'comparison_operator', 'children': ['253', '254'], 'value': 'in'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'max_i'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '255', 'type': 'comparison_operator', 'children': ['256', '257'], 'value': '>'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '257', 'type': 'integer', 'children': [], 'value': '0'},{'id': '258', 'type': 'block', 'children': ['259']},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'assignment', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'middle_index'},{'id': '262', 'type': 'call', 'children': ['263', '266']},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '266', 'type': 'argument_list', 'children': ['267']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'max_i'},{'id': '268', 'type': 'else_clause', 'children': ['269']},{'id': '269', 'type': 'block', 'children': ['270']},{'id': '270', 'type': 'break_statement', 'children': []},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'assignment', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'min_index'},{'id': '274', 'type': 'conditional_expression', 'children': ['275', '276', '279'], 'value': 'if'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'middle_index'},{'id': '276', 'type': 'comparison_operator', 'children': ['277', '278'], 'value': '=='},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'middle_index'},{'id': '278', 'type': 'integer', 'children': [], 'value': '0'},{'id': '279', 'type': 'binary_operator', 'children': ['280', '281'], 'value': '-'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'middle_index'},{'id': '281', 'type': 'integer', 'children': [], 'value': '1'},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'assignment', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'max_index'},{'id': '285', 'type': 'conditional_expression', 'children': ['286', '287', '295'], 'value': 'if'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'middle_index'},{'id': '287', 'type': 'comparison_operator', 'children': ['288', '289'], 'value': '=='},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'middle_index'},{'id': '289', 'type': 'binary_operator', 'children': ['290', '294'], 'value': '-'},{'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': 'indices'},{'id': '294', 'type': 'integer', 'children': [], 'value': '1'},{'id': '295', 'type': 'binary_operator', 'children': ['296', '297'], 'value': '+'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'middle_index'},{'id': '297', 'type': 'integer', 'children': [], 'value': '1'},{'id': '298', 'type': 'expression_statement', 'children': ['299']},{'id': '299', 'type': 'assignment', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '301', 'type': 'call', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '303', 'type': 'argument_list', 'children': ['304', '307', '310']},{'id': '304', 'type': 'subscript', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'min_index'},{'id': '307', 'type': 'subscript', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'max_index'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '311', 'type': 'return_statement', 'children': ['312']},{'id': '312', 'type': 'expression_list', 'children': ['313', '317']},{'id': '313', 'type': 'call', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '315', 'type': 'argument_list', 'children': ['316']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'max_ig'},{'id': '317', 'type': 'list', 'children': ['318', '323'], 'value': '[splits[:max_i], splits[max_i:]]'},{'id': '318', 'type': 'subscript', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'splits'},{'id': '320', 'type': 'slice', 'children': ['321', '322']},{'id': '321', 'type': 'colon', 'children': []},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'max_i'},{'id': '323', 'type': 'subscript', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'splits'},{'id': '325', 'type': 'slice', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'max_i'},{'id': '327', 'type': 'colon', 'children': []}
def info_gain_nominal(x, y, separate_max): x_vals = np.unique(x) if len(x_vals) < 3: return None y_dist = Counter(y) h_y = h(y_dist.values()) dist, splits = nominal_splits(x, y, x_vals, y_dist, separate_max) indices, repeat = (range(1, len(dist)), 1) if len(dist) < 50 else (range(1, len(dist), len(dist) / 10), 3) interval = len(dist) / 10 max_ig, max_i, iteration = 0, 1, 0 while iteration < repeat: for i in indices: dist0 = np.sum([el for el in dist[:i]]) dist1 = np.sum([el for el in dist[i:]]) coef = np.true_divide([np.sum(dist0.values()), np.sum(dist1.values())], len(y)) ig = h_y - np.dot(coef, [h(dist0.values()), h(dist1.values())]) if ig > max_ig: max_ig, max_i = ig, i iteration += 1 if repeat > 1: interval = int(interval * 0.5) if max_i in indices and interval > 0: middle_index = indices.index(max_i) else: break min_index = middle_index if middle_index == 0 else middle_index - 1 max_index = middle_index if middle_index == len(indices) - 1 else middle_index + 1 indices = range(indices[min_index], indices[max_index], interval) return float(max_ig), [splits[:max_i], splits[max_i:]]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_endpoints_using_catalog_api'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'domain'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '6', 'type': 'block', 'children': ['7', '14', '18', '22', '28', '32', '156']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '10', 'type': 'dictionary', 'children': ['11']},{'id': '11', 'type': 'pair', 'children': ['12', '13']},{'id': '12', 'type': 'string', 'children': [], 'value': '"X-App-Token"'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'uri'},{'id': '17', 'type': 'string', 'children': [], 'value': '"http://api.us.socrata.com/api/catalog/v1?domains={0}&offset={1}&limit=1000"'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '21', 'type': 'list', 'children': [], 'value': '[]'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'endpoints_thus_far'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '31', 'type': 'integer', 'children': [], 'value': '0'},{'id': '32', 'type': 'while_statement', 'children': ['33', '34']},{'id': '33', 'type': 'True', 'children': []},{'id': '34', 'type': 'block', 'children': ['35', '78', '86', '100', '109']},{'id': '35', 'type': 'try_statement', 'children': ['36', '61']},{'id': '36', 'type': 'block', 'children': ['37', '55']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '44', 'type': 'argument_list', 'children': ['45', '52']},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'uri'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'domain'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'raise_for_status'},{'id': '60', 'type': 'argument_list', 'children': []},{'id': '61', 'type': 'except_clause', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'HTTPError'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'raise_statement', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'HTTPError'},{'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': '"An HTTP error was raised during Socrata API ingestion."'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'domain'},{'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', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '85', 'type': 'argument_list', 'children': []},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'endpoints_returned'},{'id': '89', 'type': 'set_comprehension', 'children': ['90', '95']},{'id': '90', 'type': 'subscript', 'children': ['91', '94']},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '93', 'type': 'string', 'children': [], 'value': "'resource'"},{'id': '94', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '95', 'type': 'for_in_clause', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '97', 'type': 'subscript', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '99', 'type': 'string', 'children': [], 'value': "'results'"},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'new_endpoints'},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'endpoints_returned'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'difference'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'endpoints_thus_far'},{'id': '109', 'type': 'if_statement', 'children': ['110', '116', '135']},{'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': 'new_endpoints'},{'id': '115', 'type': 'integer', 'children': [], 'value': '999'},{'id': '116', 'type': 'block', 'children': ['117', '123', '130', '134']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'augmented_assignment', 'children': ['119', '120'], 'value': '+='},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '120', 'type': 'subscript', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '122', 'type': 'string', 'children': [], 'value': "'results'"},{'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': 'endpoints_thus_far'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'new_endpoints'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'augmented_assignment', 'children': ['132', '133'], 'value': '+='},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '133', 'type': 'integer', 'children': [], 'value': '1000'},{'id': '134', 'type': 'continue_statement', 'children': []},{'id': '135', 'type': 'else_clause', 'children': ['136']},{'id': '136', 'type': 'block', 'children': ['137', '155']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'augmented_assignment', 'children': ['139', '140'], 'value': '+='},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '140', 'type': 'list_comprehension', 'children': ['141', '142', '147']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '142', 'type': 'for_in_clause', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '144', 'type': 'subscript', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '146', 'type': 'string', 'children': [], 'value': "'results'"},{'id': '147', 'type': 'if_clause', 'children': ['148']},{'id': '148', 'type': 'comparison_operator', 'children': ['149', '154'], 'value': 'in'},{'id': '149', 'type': 'subscript', 'children': ['150', '153']},{'id': '150', 'type': 'subscript', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '152', 'type': 'string', 'children': [], 'value': "'resource'"},{'id': '153', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'new_endpoints'},{'id': '155', 'type': 'break_statement', 'children': []},{'id': '156', 'type': 'return_statement', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'ret'}
def get_endpoints_using_catalog_api(domain, token): headers = {"X-App-Token": token} uri = "http://api.us.socrata.com/api/catalog/v1?domains={0}&offset={1}&limit=1000" ret = [] endpoints_thus_far = set() offset = 0 while True: try: r = requests.get(uri.format(domain, offset), headers=headers) r.raise_for_status() except requests.HTTPError: raise requests.HTTPError("An HTTP error was raised during Socrata API ingestion.".format(domain)) data = r.json() endpoints_returned = {r['resource']['id'] for r in data['results']} new_endpoints = endpoints_returned.difference(endpoints_thus_far) if len(new_endpoints) >= 999: ret += data['results'] endpoints_thus_far.update(new_endpoints) offset += 1000 continue else: ret += [r for r in data['results'] if r['resource']['id'] in new_endpoints] break return ret
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'stratify_by_scores'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'goal_n_strata'},{'id': '7', 'type': 'string', 'children': [], 'value': "'auto'"},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '10', 'type': 'string', 'children': [], 'value': "'cum_sqrt_F'"},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'n_bins'},{'id': '13', 'type': 'string', 'children': [], 'value': "'auto'"},{'id': '14', 'type': 'block', 'children': ['15', '21', '31', '174', '280', '470']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'available_methods'},{'id': '18', 'type': 'list', 'children': ['19', '20'], 'value': "['equal_size', 'cum_sqrt_F']"},{'id': '19', 'type': 'string', 'children': [], 'value': "'equal_size'"},{'id': '20', 'type': 'string', 'children': [], 'value': "'cum_sqrt_F'"},{'id': '21', 'type': 'if_statement', 'children': ['22', '25']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'not'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'available_methods'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'raise_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'string', 'children': [], 'value': '"method argument is invalid"'},{'id': '31', 'type': 'if_statement', 'children': ['32', '41']},{'id': '32', 'type': 'boolean_operator', 'children': ['33', '37'], 'value': 'or'},{'id': '33', 'type': '()', 'children': ['34']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': '=='},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '36', 'type': 'string', 'children': [], 'value': "'cum_sqrt_F'"},{'id': '37', 'type': '()', 'children': ['38']},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': '=='},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'goal_n_strata'},{'id': '40', 'type': 'string', 'children': [], 'value': "'auto'"},{'id': '41', 'type': 'block', 'children': ['42', '85', '99', '108', '117']},{'id': '42', 'type': 'if_statement', 'children': ['43', '46']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': '=='},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'n_bins'},{'id': '45', 'type': 'string', 'children': [], 'value': "'auto'"},{'id': '46', 'type': 'block', 'children': ['47', '54', '75']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'width_score'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': '_heuristic_bin_width'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'n_bins'},{'id': '57', 'type': 'call', 'children': ['58', '73']},{'id': '58', 'type': 'attribute', 'children': ['59', '72']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'ceil'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'binary_operator', 'children': ['65', '71'], 'value': '/'},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'sp'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'ptp'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'width_score'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'int'},{'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': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'string', 'children': [], 'value': '"Automatically setting n_bins = {}."'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'n_bins'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '90']},{'id': '87', 'type': 'pattern_list', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'score_bins'},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'histogram'},{'id': '94', 'type': 'argument_list', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'n_bins'},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'sqrt_counts'},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'sqrt'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'csf'},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'cumsum'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'sqrt_counts'},{'id': '117', 'type': 'if_statement', 'children': ['118', '121', '160']},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': '=='},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'goal_n_strata'},{'id': '120', 'type': 'string', 'children': [], 'value': "'auto'"},{'id': '121', 'type': 'block', 'children': ['122', '129', '150']},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'width_csf'},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': '_heuristic_bin_width'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'csf'},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'goal_n_strata'},{'id': '132', 'type': 'call', 'children': ['133', '148']},{'id': '133', 'type': 'attribute', 'children': ['134', '147']},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'ceil'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'binary_operator', 'children': ['140', '146'], 'value': '/'},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'sp'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'ptp'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'csf'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'width_csf'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'string', 'children': [], 'value': '"Automatically setting goal_n_strata = {}."'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'goal_n_strata'},{'id': '160', 'type': 'elif_clause', 'children': ['161', '164']},{'id': '161', 'type': 'comparison_operator', 'children': ['162', '163'], 'value': '=='},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '163', 'type': 'string', 'children': [], 'value': "'cum_sqrt_F'"},{'id': '164', 'type': 'block', 'children': ['165']},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'width_csf'},{'id': '168', 'type': 'binary_operator', 'children': ['169', '173'], 'value': '/'},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'csf'},{'id': '171', 'type': 'unary_operator', 'children': ['172'], 'value': '-'},{'id': '172', 'type': 'integer', 'children': [], 'value': '1'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'goal_n_strata'},{'id': '174', 'type': 'if_statement', 'children': ['175', '178']},{'id': '175', 'type': 'comparison_operator', 'children': ['176', '177'], 'value': '=='},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '177', 'type': 'string', 'children': [], 'value': "'equal_size'"},{'id': '178', 'type': 'block', 'children': ['179', '187', '194', '200', '206', '218', '229', '242', '246']},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'sorted_ids'},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '186', 'type': 'argument_list', 'children': []},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'n_items'},{'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': 'sorted_ids'},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'quotient'},{'id': '197', 'type': 'binary_operator', 'children': ['198', '199'], 'value': '//'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'n_items'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'goal_n_strata'},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'remainder'},{'id': '203', 'type': 'binary_operator', 'children': ['204', '205'], 'value': '%'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'n_items'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'goal_n_strata'},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'allocations'},{'id': '209', 'type': 'call', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'empty'},{'id': '213', 'type': 'argument_list', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'n_items'},{'id': '215', 'type': 'keyword_argument', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '217', 'type': 'string', 'children': [], 'value': "'int'"},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'assignment', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'st_pops'},{'id': '221', 'type': 'list_comprehension', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'quotient'},{'id': '223', 'type': 'for_in_clause', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '225', 'type': 'call', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'goal_n_strata'},{'id': '229', 'type': 'for_statement', 'children': ['230', '231', '235']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '231', 'type': 'call', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'remainder'},{'id': '235', 'type': 'block', 'children': ['236']},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'augmented_assignment', 'children': ['238', '241'], 'value': '+='},{'id': '238', 'type': 'subscript', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'st_pops'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '241', 'type': 'integer', 'children': [], 'value': '1'},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'assignment', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '245', 'type': 'integer', 'children': [], 'value': '0'},{'id': '246', 'type': 'for_statement', 'children': ['247', '250', '254']},{'id': '247', 'type': 'pattern_list', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'nk'},{'id': '250', 'type': 'call', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '252', 'type': 'argument_list', 'children': ['253']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'st_pops'},{'id': '254', 'type': 'block', 'children': ['255', '259', '265', '276']},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'assignment', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'assignment', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '262', 'type': 'binary_operator', 'children': ['263', '264'], 'value': '+'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'nk'},{'id': '265', 'type': 'expression_statement', 'children': ['266']},{'id': '266', 'type': 'assignment', 'children': ['267', '275']},{'id': '267', 'type': 'subscript', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'allocations'},{'id': '269', 'type': 'subscript', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'sorted_ids'},{'id': '271', 'type': 'slice', 'children': ['272', '273', '274']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '273', 'type': 'colon', 'children': []},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '276', 'type': 'expression_statement', 'children': ['277']},{'id': '277', 'type': 'assignment', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '280', 'type': 'if_statement', 'children': ['281', '284']},{'id': '281', 'type': 'comparison_operator', 'children': ['282', '283'], 'value': '=='},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '283', 'type': 'string', 'children': [], 'value': "'cum_sqrt_F'"},{'id': '284', 'type': 'block', 'children': ['285', '299', '316', '320', '324', '385', '391', '398', '415', '424', '431', '440', '453']},{'id': '285', 'type': 'if_statement', 'children': ['286', '289']},{'id': '286', 'type': 'comparison_operator', 'children': ['287', '288'], 'value': '>'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'goal_n_strata'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'n_bins'},{'id': '289', 'type': 'block', 'children': ['290']},{'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': 'warnings'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '295', 'type': 'argument_list', 'children': ['296']},{'id': '296', 'type': 'concatenated_string', 'children': ['297', '298']},{'id': '297', 'type': 'string', 'children': [], 'value': '"goal_n_strata > n_bins. "'},{'id': '298', 'type': 'string', 'children': [], 'value': '"Consider increasing n_bins."'},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'assignment', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'csf_bins'},{'id': '302', 'type': 'list_comprehension', 'children': ['303', '306']},{'id': '303', 'type': 'binary_operator', 'children': ['304', '305'], 'value': '*'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'width_csf'},{'id': '306', 'type': 'for_in_clause', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'x'},{'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': 'arange'},{'id': '312', 'type': 'argument_list', 'children': ['313']},{'id': '313', 'type': 'binary_operator', 'children': ['314', '315'], 'value': '+'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'goal_n_strata'},{'id': '315', 'type': 'integer', 'children': [], 'value': '1'},{'id': '316', 'type': 'expression_statement', 'children': ['317']},{'id': '317', 'type': 'assignment', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '319', 'type': 'integer', 'children': [], 'value': '0'},{'id': '320', 'type': 'expression_statement', 'children': ['321']},{'id': '321', 'type': 'assignment', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'new_bins'},{'id': '323', 'type': 'list', 'children': [], 'value': '[]'},{'id': '324', 'type': 'for_statement', 'children': ['325', '328', '332']},{'id': '325', 'type': 'tuple_pattern', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '328', 'type': 'call', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '330', 'type': 'argument_list', 'children': ['331']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'csf'},{'id': '332', 'type': 'block', 'children': ['333', '365']},{'id': '333', 'type': 'if_statement', 'children': ['334', '353']},{'id': '334', 'type': 'boolean_operator', 'children': ['335', '344'], 'value': 'or'},{'id': '335', 'type': 'comparison_operator', 'children': ['336', '337'], 'value': '=='},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '337', 'type': '()', 'children': ['338']},{'id': '338', 'type': 'binary_operator', 'children': ['339', '343'], 'value': '-'},{'id': '339', 'type': 'call', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '341', 'type': 'argument_list', 'children': ['342']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'csf_bins'},{'id': '343', 'type': 'integer', 'children': [], 'value': '1'},{'id': '344', 'type': 'comparison_operator', 'children': ['345', '346'], 'value': '=='},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '346', 'type': '()', 'children': ['347']},{'id': '347', 'type': 'binary_operator', 'children': ['348', '352'], 'value': '-'},{'id': '348', 'type': 'call', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '350', 'type': 'argument_list', 'children': ['351']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'csf'},{'id': '352', 'type': 'integer', 'children': [], 'value': '1'},{'id': '353', 'type': 'block', 'children': ['354', '364']},{'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': 'new_bins'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '359', 'type': 'argument_list', 'children': ['360']},{'id': '360', 'type': 'subscript', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'score_bins'},{'id': '362', 'type': 'unary_operator', 'children': ['363'], 'value': '-'},{'id': '363', 'type': 'integer', 'children': [], 'value': '1'},{'id': '364', 'type': 'break_statement', 'children': []},{'id': '365', 'type': 'if_statement', 'children': ['366', '371']},{'id': '366', 'type': 'comparison_operator', 'children': ['367', '368'], 'value': '>='},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '368', 'type': 'subscript', 'children': ['369', '370']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'csf_bins'},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '371', 'type': 'block', 'children': ['372', '381']},{'id': '372', 'type': 'expression_statement', 'children': ['373']},{'id': '373', 'type': 'call', 'children': ['374', '377']},{'id': '374', 'type': 'attribute', 'children': ['375', '376']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'new_bins'},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '377', 'type': 'argument_list', 'children': ['378']},{'id': '378', 'type': 'subscript', 'children': ['379', '380']},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'score_bins'},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '381', 'type': 'expression_statement', 'children': ['382']},{'id': '382', 'type': 'augmented_assignment', 'children': ['383', '384'], 'value': '+='},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '384', 'type': 'integer', 'children': [], 'value': '1'},{'id': '385', 'type': 'expression_statement', 'children': ['386']},{'id': '386', 'type': 'augmented_assignment', 'children': ['387', '390'], 'value': '-='},{'id': '387', 'type': 'subscript', 'children': ['388', '389']},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'new_bins'},{'id': '389', 'type': 'integer', 'children': [], 'value': '0'},{'id': '390', 'type': 'float', 'children': [], 'value': '0.01'},{'id': '391', 'type': 'expression_statement', 'children': ['392']},{'id': '392', 'type': 'augmented_assignment', 'children': ['393', '397'], 'value': '+='},{'id': '393', 'type': 'subscript', 'children': ['394', '395']},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'new_bins'},{'id': '395', 'type': 'unary_operator', 'children': ['396'], 'value': '-'},{'id': '396', 'type': 'integer', 'children': [], 'value': '1'},{'id': '397', 'type': 'float', 'children': [], 'value': '0.01'},{'id': '398', 'type': 'expression_statement', 'children': ['399']},{'id': '399', 'type': 'assignment', 'children': ['400', '401']},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'allocations'},{'id': '401', 'type': 'binary_operator', 'children': ['402', '414'], 'value': '-'},{'id': '402', 'type': 'call', 'children': ['403', '406']},{'id': '403', 'type': 'attribute', 'children': ['404', '405']},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '405', 'type': 'identifier', 'children': [], 'value': 'digitize'},{'id': '406', 'type': 'argument_list', 'children': ['407', '408', '411']},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '408', 'type': 'keyword_argument', 'children': ['409', '410']},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'new_bins'},{'id': '411', 'type': 'keyword_argument', 'children': ['412', '413']},{'id': '412', 'type': 'identifier', 'children': [], 'value': 'right'},{'id': '413', 'type': 'True', 'children': []},{'id': '414', 'type': 'integer', 'children': [], 'value': '1'},{'id': '415', 'type': 'expression_statement', 'children': ['416']},{'id': '416', 'type': 'assignment', 'children': ['417', '418']},{'id': '417', 'type': 'identifier', 'children': [], 'value': 'nonempty_ids'},{'id': '418', 'type': 'call', 'children': ['419', '422']},{'id': '419', 'type': 'attribute', 'children': ['420', '421']},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '422', 'type': 'argument_list', 'children': ['423']},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'allocations'},{'id': '424', 'type': 'expression_statement', 'children': ['425']},{'id': '425', 'type': 'assignment', 'children': ['426', '427']},{'id': '426', 'type': 'identifier', 'children': [], 'value': 'n_strata'},{'id': '427', 'type': 'call', 'children': ['428', '429']},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '429', 'type': 'argument_list', 'children': ['430']},{'id': '430', 'type': 'identifier', 'children': [], 'value': 'nonempty_ids'},{'id': '431', 'type': 'expression_statement', 'children': ['432']},{'id': '432', 'type': 'assignment', 'children': ['433', '434']},{'id': '433', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '434', 'type': 'call', 'children': ['435', '438']},{'id': '435', 'type': 'attribute', 'children': ['436', '437']},{'id': '436', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '437', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '438', 'type': 'argument_list', 'children': ['439']},{'id': '439', 'type': 'identifier', 'children': [], 'value': 'n_strata'},{'id': '440', 'type': 'expression_statement', 'children': ['441']},{'id': '441', 'type': 'assignment', 'children': ['442', '443']},{'id': '442', 'type': 'identifier', 'children': [], 'value': 'allocations'},{'id': '443', 'type': 'call', 'children': ['444', '447']},{'id': '444', 'type': 'attribute', 'children': ['445', '446']},{'id': '445', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '446', 'type': 'identifier', 'children': [], 'value': 'digitize'},{'id': '447', 'type': 'argument_list', 'children': ['448', '449', '450']},{'id': '448', 'type': 'identifier', 'children': [], 'value': 'allocations'},{'id': '449', 'type': 'identifier', 'children': [], 'value': 'nonempty_ids'},{'id': '450', 'type': 'keyword_argument', 'children': ['451', '452']},{'id': '451', 'type': 'identifier', 'children': [], 'value': 'right'},{'id': '452', 'type': 'True', 'children': []},{'id': '453', 'type': 'if_statement', 'children': ['454', '457']},{'id': '454', 'type': 'comparison_operator', 'children': ['455', '456'], 'value': '<'},{'id': '455', 'type': 'identifier', 'children': [], 'value': 'n_strata'},{'id': '456', 'type': 'identifier', 'children': [], 'value': 'goal_n_strata'},{'id': '457', 'type': 'block', 'children': ['458']},{'id': '458', 'type': 'expression_statement', 'children': ['459']},{'id': '459', 'type': 'call', 'children': ['460', '463']},{'id': '460', 'type': 'attribute', 'children': ['461', '462']},{'id': '461', 'type': 'identifier', 'children': [], 'value': 'warnings'},{'id': '462', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '463', 'type': 'argument_list', 'children': ['464']},{'id': '464', 'type': 'call', 'children': ['465', '468']},{'id': '465', 'type': 'attribute', 'children': ['466', '467']},{'id': '466', 'type': 'string', 'children': [], 'value': '"Failed to create {} strata"'},{'id': '467', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '468', 'type': 'argument_list', 'children': ['469']},{'id': '469', 'type': 'identifier', 'children': [], 'value': 'goal_n_strata'},{'id': '470', 'type': 'return_statement', 'children': ['471']},{'id': '471', 'type': 'call', 'children': ['472', '473']},{'id': '472', 'type': 'identifier', 'children': [], 'value': 'Strata'},{'id': '473', 'type': 'argument_list', 'children': ['474']},{'id': '474', 'type': 'identifier', 'children': [], 'value': 'allocations'}
def stratify_by_scores(scores, goal_n_strata='auto', method='cum_sqrt_F', n_bins = 'auto'): available_methods = ['equal_size', 'cum_sqrt_F'] if method not in available_methods: raise ValueError("method argument is invalid") if (method == 'cum_sqrt_F') or (goal_n_strata == 'auto'): if n_bins == 'auto': width_score = _heuristic_bin_width(scores) n_bins = np.ceil(sp.ptp(scores)/width_score).astype(int) print("Automatically setting n_bins = {}.".format(n_bins)) counts, score_bins = np.histogram(scores, bins=n_bins) sqrt_counts = np.sqrt(counts) csf = np.cumsum(sqrt_counts) if goal_n_strata == 'auto': width_csf = _heuristic_bin_width(csf) goal_n_strata = np.ceil(sp.ptp(csf)/width_csf).astype(int) print("Automatically setting goal_n_strata = {}.".format(goal_n_strata)) elif method == 'cum_sqrt_F': width_csf = csf[-1]/goal_n_strata if method == 'equal_size': sorted_ids = scores.argsort() n_items = len(sorted_ids) quotient = n_items // goal_n_strata remainder = n_items % goal_n_strata allocations = np.empty(n_items, dtype='int') st_pops = [quotient for i in range(goal_n_strata)] for i in range(remainder): st_pops[i] += 1 j = 0 for k,nk in enumerate(st_pops): start = j end = j + nk allocations[sorted_ids[start:end]] = k j = end if method == 'cum_sqrt_F': if goal_n_strata > n_bins: warnings.warn("goal_n_strata > n_bins. " "Consider increasing n_bins.") csf_bins = [x * width_csf for x in np.arange(goal_n_strata + 1)] j = 0 new_bins = [] for (idx,value) in enumerate(csf): if j == (len(csf_bins) - 1) or idx == (len(csf) - 1): new_bins.append(score_bins[-1]) break if value >= csf_bins[j]: new_bins.append(score_bins[idx]) j += 1 new_bins[0] -= 0.01 new_bins[-1] += 0.01 allocations = np.digitize(scores, bins=new_bins, right=True) - 1 nonempty_ids = np.unique(allocations) n_strata = len(nonempty_ids) indices = np.arange(n_strata) allocations = np.digitize(allocations, nonempty_ids, right=True) if n_strata < goal_n_strata: warnings.warn("Failed to create {} strata".format(goal_n_strata)) return Strata(allocations)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_target'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '6', 'type': 'block', 'children': ['7', '18', '28', '50', '95']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '10', 'type': 'binary_operator', 'children': ['11', '17'], 'value': '+'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '17', 'type': 'integer', 'children': [], 'value': '1'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'target'},{'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': 'for_statement', 'children': ['29', '30', '33']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'modules'},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'if_statement', 'children': ['35', '42']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '39'], 'value': '=='},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '38', 'type': 'integer', 'children': [], 'value': '0'},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'if_statement', 'children': ['44', '47']},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': '<'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '46', 'type': 'integer', 'children': [], 'value': '3'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'return_statement', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '50', 'type': 'for_statement', 'children': ['51', '52', '55']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'packages'},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'if_statement', 'children': ['57', '64']},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '61'], 'value': '=='},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '60', 'type': 'integer', 'children': [], 'value': '0'},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '64', 'type': 'block', 'children': ['65', '72', '83', '88']},{'id': '65', 'type': 'if_statement', 'children': ['66', '69']},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': '=='},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '68', 'type': 'integer', 'children': [], 'value': '1'},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'return_statement', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '78', 'type': 'identifier', 'children': [], 'value': '_get_target'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '82', 'type': 'integer', 'children': [], 'value': '1'},{'id': '83', 'type': 'if_statement', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'return_statement', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '88', 'type': 'if_statement', 'children': ['89', '92']},{'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': '<'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '91', 'type': 'integer', 'children': [], 'value': '3'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'return_statement', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '95', 'type': 'return_statement', 'children': ['96']},{'id': '96', 'type': 'None', 'children': []}
def _get_target(self, target): depth = target.count('.') + 1 parts = target.split('.', 1) for m in self.modules: if parts[0] == m.name: if depth < 3: return m for p in self.packages: if parts[0] == p.name: if depth == 1: return p target = p._get_target(parts[1]) if target: return target if depth < 3: return p return None
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'by_user'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '5', 'type': 'block', 'children': ['6', '12', '18', '25']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'Client'},{'id': '11', 'type': 'argument_list', 'children': []},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'prepare_connection'},{'id': '17', 'type': 'argument_list', 'children': []},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'audit_api'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'API'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'client'},{'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': 'CLI'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'parse_membership'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32']},{'id': '31', 'type': 'string', 'children': [], 'value': "'Groups by User'"},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'audit_api'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'by_user'},{'id': '36', 'type': 'argument_list', 'children': []}
def by_user(config): client = Client() client.prepare_connection() audit_api = API(client) CLI.parse_membership('Groups by User', audit_api.by_user())
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_sortkey'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '5', 'type': 'block', 'children': ['6', '20']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'wfs'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'WebFeatureService'},{'id': '11', 'type': 'argument_list', 'children': ['12', '17']},{'id': '12', 'type': 'keyword_argument', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'bcdata'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'OWS_URL'},{'id': '17', 'type': 'keyword_argument', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '19', 'type': 'string', 'children': [], 'value': '"2.0.0"'},{'id': '20', 'type': 'return_statement', 'children': ['21']},{'id': '21', 'type': 'subscript', 'children': ['22', '39']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '38']},{'id': '26', 'type': 'attribute', 'children': ['27', '37']},{'id': '27', 'type': 'subscript', 'children': ['28', '36']},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'wfs'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'get_schema'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '+'},{'id': '34', 'type': 'string', 'children': [], 'value': '"pub:"'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '36', 'type': 'string', 'children': [], 'value': '"properties"'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '38', 'type': 'argument_list', 'children': []},{'id': '39', 'type': 'integer', 'children': [], 'value': '0'}
def get_sortkey(table): wfs = WebFeatureService(url=bcdata.OWS_URL, version="2.0.0") return sorted(wfs.get_schema("pub:" + table)["properties"].keys())[0]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'define_request'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'crs'},{'id': '10', 'type': 'string', 'children': [], 'value': '"epsg:4326"'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'bounds'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sortby'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'pagesize'},{'id': '19', 'type': 'integer', 'children': [], 'value': '10000'},{'id': '20', 'type': 'block', 'children': ['21', '28', '40', '51', '66', '70', '164']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'validate_name'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'bcdata'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'get_count'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'math'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'ceil'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'binary_operator', 'children': ['49', '50'], 'value': '/'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'pagesize'},{'id': '51', 'type': 'if_statement', 'children': ['52', '58']},{'id': '52', 'type': 'boolean_operator', 'children': ['53', '56'], 'value': 'and'},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': '>'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '55', 'type': 'integer', 'children': [], 'value': '1'},{'id': '56', 'type': 'not_operator', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'sortby'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'sortby'},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'get_sortkey'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'param_dicts'},{'id': '69', 'type': 'list', 'children': [], 'value': '[]'},{'id': '70', 'type': 'for_statement', 'children': ['71', '72', '76']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '76', 'type': 'block', 'children': ['77', '99', '108', '117', '138', '157']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '80', 'type': 'dictionary', 'children': ['81', '84', '87', '90', '93', '96']},{'id': '81', 'type': 'pair', 'children': ['82', '83']},{'id': '82', 'type': 'string', 'children': [], 'value': '"service"'},{'id': '83', 'type': 'string', 'children': [], 'value': '"WFS"'},{'id': '84', 'type': 'pair', 'children': ['85', '86']},{'id': '85', 'type': 'string', 'children': [], 'value': '"version"'},{'id': '86', 'type': 'string', 'children': [], 'value': '"2.0.0"'},{'id': '87', 'type': 'pair', 'children': ['88', '89']},{'id': '88', 'type': 'string', 'children': [], 'value': '"request"'},{'id': '89', 'type': 'string', 'children': [], 'value': '"GetFeature"'},{'id': '90', 'type': 'pair', 'children': ['91', '92']},{'id': '91', 'type': 'string', 'children': [], 'value': '"typeName"'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '93', 'type': 'pair', 'children': ['94', '95']},{'id': '94', 'type': 'string', 'children': [], 'value': '"outputFormat"'},{'id': '95', 'type': 'string', 'children': [], 'value': '"json"'},{'id': '96', 'type': 'pair', 'children': ['97', '98']},{'id': '97', 'type': 'string', 'children': [], 'value': '"SRSNAME"'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'crs'},{'id': '99', 'type': 'if_statement', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'sortby'},{'id': '101', 'type': 'block', 'children': ['102']},{'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': 'request'},{'id': '106', 'type': 'string', 'children': [], 'value': '"sortby"'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'sortby'},{'id': '108', 'type': 'if_statement', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '116']},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '115', 'type': 'string', 'children': [], 'value': '"CQL_FILTER"'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '117', 'type': 'if_statement', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'bounds'},{'id': '119', 'type': 'block', 'children': ['120']},{'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': 'request'},{'id': '124', 'type': 'string', 'children': [], 'value': '"bbox"'},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'string', 'children': [], 'value': '","'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'list_comprehension', 'children': ['131', '135']},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '135', 'type': 'for_in_clause', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'bounds'},{'id': '138', 'type': 'if_statement', 'children': ['139', '142']},{'id': '139', 'type': 'comparison_operator', 'children': ['140', '141'], 'value': '>'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '141', 'type': 'integer', 'children': [], 'value': '1'},{'id': '142', 'type': 'block', 'children': ['143', '151']},{'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': 'request'},{'id': '147', 'type': 'string', 'children': [], 'value': '"startIndex"'},{'id': '148', 'type': 'binary_operator', 'children': ['149', '150'], 'value': '*'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'pagesize'},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '156']},{'id': '153', 'type': 'subscript', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '155', 'type': 'string', 'children': [], 'value': '"count"'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'pagesize'},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'call', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'param_dicts'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '164', 'type': 'return_statement', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'param_dicts'}
def define_request( dataset, query=None, crs="epsg:4326", bounds=None, sortby=None, pagesize=10000 ): table = validate_name(dataset) n = bcdata.get_count(table, query=query) chunks = math.ceil(n / pagesize) if chunks > 1 and not sortby: sortby = get_sortkey(table) param_dicts = [] for i in range(chunks): request = { "service": "WFS", "version": "2.0.0", "request": "GetFeature", "typeName": table, "outputFormat": "json", "SRSNAME": crs, } if sortby: request["sortby"] = sortby if query: request["CQL_FILTER"] = query if bounds: request["bbox"] = ",".join([str(b) for b in bounds]) if chunks > 1: request["startIndex"] = i * pagesize request["count"] = pagesize param_dicts.append(request) return param_dicts
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_sorted'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'resources'},{'id': '6', 'type': 'block', 'children': ['7', '11', '48']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '10', 'type': 'list', 'children': [], 'value': '[]'},{'id': '11', 'type': 'for_statement', 'children': ['12', '13', '14']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'resources'},{'id': '14', 'type': 'block', 'children': ['15', '21', '39']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_path'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '24', 'type': 'binary_operator', 'children': ['25', '33'], 'value': '-'},{'id': '25', 'type': 'binary_operator', 'children': ['26', '32'], 'value': '*'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '32', 'type': 'integer', 'children': [], 'value': '10'},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'string', 'children': [], 'value': "'{'"},{'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': 'tmp'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'tuple', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '48', 'type': 'return_statement', 'children': ['49']},{'id': '49', 'type': 'list_comprehension', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '51', 'type': 'for_in_clause', 'children': ['52', '55']},{'id': '52', 'type': 'pattern_list', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'prio'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'reversed'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'tmp'}
def _get_sorted(self, resources): tmp = [] for resource in resources: path = resource._path priority = path.count('/') * 10 - path.count('{') tmp.append((priority, resource)) return [resource for prio, resource in reversed(sorted(tmp))]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_new_posts_and_pages'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '5', 'type': 'block', 'children': ['6', '12']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'Q'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'Query'},{'id': '11', 'type': 'argument_list', 'children': []},{'id': '12', 'type': 'for_statement', 'children': ['13', '17', '25']},{'id': '13', 'type': 'pattern_list', 'children': ['14', '15', '16']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'files'},{'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': 'walk'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'subscript', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'CONFIG'},{'id': '24', 'type': 'string', 'children': [], 'value': "'content_root'"},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'for_statement', 'children': ['27', '28', '45']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'list_comprehension', 'children': ['32', '33', '36']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '33', 'type': 'for_in_clause', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '36', 'type': 'if_clause', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'tuple', 'children': ['43', '44']},{'id': '43', 'type': 'string', 'children': [], 'value': "'md'"},{'id': '44', 'type': 'string', 'children': [], 'value': "'markdown'"},{'id': '45', 'type': 'block', 'children': ['46', '58', '77', '91', '99', '161', '172']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'fullpath'},{'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': 'os'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '55', 'type': 'argument_list', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': '_p'},{'id': '61', 'type': 'call', 'children': ['62', '75']},{'id': '62', 'type': 'attribute', 'children': ['63', '74']},{'id': '63', 'type': 'subscript', 'children': ['64', '72']},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'fullpath'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'subscript', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'CONFIG'},{'id': '71', 'type': 'string', 'children': [], 'value': "'content_root'"},{'id': '72', 'type': 'unary_operator', 'children': ['73'], 'value': '-'},{'id': '73', 'type': 'integer', 'children': [], 'value': '1'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'lstrip'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'new_mtime'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '89']},{'id': '84', 'type': 'attribute', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'getmtime'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'fullpath'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '96']},{'id': '93', 'type': 'pattern_list', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '96', 'type': 'expression_list', 'children': ['97', '98']},{'id': '97', 'type': 'None', 'children': []},{'id': '98', 'type': 'None', 'children': []},{'id': '99', 'type': 'for_statement', 'children': ['100', '101', '104']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '101', 'type': 'list', 'children': ['102', '103'], 'value': "['posts', 'pages']"},{'id': '102', 'type': 'string', 'children': [], 'value': "'posts'"},{'id': '103', 'type': 'string', 'children': [], 'value': "'pages'"},{'id': '104', 'type': 'block', 'children': ['105', '120']},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '108', 'type': 'call', 'children': ['109', '114']},{'id': '109', 'type': 'attribute', 'children': ['110', '113']},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'comparison_operator', 'children': ['116', '119'], 'value': '=='},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'Q'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '119', 'type': 'identifier', 'children': [], 'value': '_p'},{'id': '120', 'type': 'if_statement', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '122', 'type': 'block', 'children': ['123', '160']},{'id': '123', 'type': 'if_statement', 'children': ['124', '129']},{'id': '124', 'type': 'comparison_operator', 'children': ['125', '126'], 'value': '>'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'new_mtime'},{'id': '126', 'type': 'subscript', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '128', 'type': 'string', 'children': [], 'value': "'mtime'"},{'id': '129', 'type': 'block', 'children': ['130', '148']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '137']},{'id': '132', 'type': 'attribute', 'children': ['133', '136']},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '137', 'type': 'argument_list', 'children': ['138', '142']},{'id': '138', 'type': 'dictionary', 'children': ['139']},{'id': '139', 'type': 'pair', 'children': ['140', '141']},{'id': '140', 'type': 'string', 'children': [], 'value': "'mtime'"},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'new_mtime'},{'id': '142', 'type': 'keyword_argument', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'doc_ids'},{'id': '144', 'type': 'list', 'children': ['145'], 'value': '[item.doc_id]'},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'doc_id'},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'Entry'},{'id': '153', 'type': 'argument_list', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'fullpath'},{'id': '155', 'type': 'keyword_argument', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'doc_id'},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'doc_id'},{'id': '160', 'type': 'break_statement', 'children': []},{'id': '161', 'type': 'if_statement', 'children': ['162', '164']},{'id': '162', 'type': 'not_operator', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '164', 'type': 'block', 'children': ['165']},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'Entry'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'fullpath'},{'id': '172', 'type': 'if_statement', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '174', 'type': 'block', 'children': ['175']},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'yield', 'children': ['177']},{'id': '177', 'type': 'expression_list', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'id'}
def find_new_posts_and_pages(db): Q = Query() for root, dirs, files in os.walk(CONFIG['content_root']): for filename in sorted([f for f in files if f.endswith(('md', 'markdown'))]): fullpath = os.path.join(root, filename) _p = fullpath.split(CONFIG['content_root'])[-1].lstrip('/') new_mtime = int(os.path.getmtime(fullpath)) e, item = None, None for collection in ['posts', 'pages']: item = db[collection].get(Q.filename == _p) if item: if new_mtime > item['mtime']: db[collection].update({'mtime': new_mtime}, doc_ids=[item.doc_id]) e = Entry(fullpath, doc_id=item.doc_id) break if not item: e = Entry(fullpath) if e: yield e, e.id
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_locations'},{'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': 'filter_to_my_group'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '19', '23', '60', '64', '199']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': '_post'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'string', 'children': [], 'value': "'general-retrievelocations'"},{'id': '18', 'type': 'string', 'children': [], 'value': "'locations'"},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '22', 'type': 'dictionary', 'children': []},{'id': '23', 'type': 'if_statement', 'children': ['24', '27']},{'id': '24', 'type': 'subscript', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '26', 'type': 'string', 'children': [], 'value': "'groupinfo'"},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'for_statement', 'children': ['29', '30', '33']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '30', 'type': 'subscript', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '32', 'type': 'string', 'children': [], 'value': "'groupinfo'"},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '41']},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '38', 'type': 'subscript', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '40', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'Group'},{'id': '43', 'type': 'argument_list', 'children': ['44', '52']},{'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'inventory_id'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'final_resp'},{'id': '63', 'type': 'list', 'children': [], 'value': '[]'},{'id': '64', 'type': 'if_statement', 'children': ['65', '68']},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '67', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '68', 'type': 'block', 'children': ['69', '89']},{'id': '69', 'type': 'if_statement', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'filter_to_my_group'},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '77']},{'id': '74', 'type': 'subscript', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '76', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '77', 'type': 'dictionary', 'children': ['78']},{'id': '78', 'type': 'pair', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'groupid'},{'id': '82', 'type': 'subscript', 'children': ['83', '86']},{'id': '83', 'type': 'subscript', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '85', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'groupid'},{'id': '89', 'type': 'for_statement', 'children': ['90', '93', '100']},{'id': '90', 'type': 'pattern_list', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'groupid'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'sublocation'},{'id': '93', 'type': 'call', 'children': ['94', '99']},{'id': '94', 'type': 'attribute', 'children': ['95', '98']},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '97', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '99', 'type': 'argument_list', 'children': []},{'id': '100', 'type': 'block', 'children': ['101', '130', '145']},{'id': '101', 'type': 'if_statement', 'children': ['102', '108']},{'id': '102', 'type': 'comparison_operator', 'children': ['103', '107'], 'value': 'is'},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'sublocation'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '108', 'type': 'block', 'children': ['109', '123']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'sublocation'},{'id': '112', 'type': 'list_comprehension', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '114', 'type': 'for_in_clause', 'children': ['115', '118']},{'id': '115', 'type': 'pattern_list', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'sublocation'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '122', 'type': 'argument_list', 'children': []},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'sublocation'},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'flatten_list'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'sublocation'},{'id': '130', 'type': 'if_statement', 'children': ['131', '137']},{'id': '131', 'type': 'comparison_operator', 'children': ['132', '136'], 'value': 'is'},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'sublocation'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '137', 'type': 'block', 'children': ['138']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'sublocation'},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'flatten_list'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'sublocation'},{'id': '145', 'type': 'for_statement', 'children': ['146', '147', '148']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'sublocation'},{'id': '148', 'type': 'block', 'children': ['149', '155']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'groupid'},{'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': 'final_resp'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'Location'},{'id': '163', 'type': 'argument_list', 'children': ['164', '172', '180', '188', '191']},{'id': '164', 'type': 'keyword_argument', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '172', 'type': 'keyword_argument', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'inventory_id'},{'id': '174', 'type': 'call', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '180', 'type': 'keyword_argument', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'string', 'children': [], 'value': "'parent'"},{'id': '188', 'type': 'keyword_argument', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '191', 'type': 'keyword_argument', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'barcode'},{'id': '193', 'type': 'call', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'string', 'children': [], 'value': "'barcode'"},{'id': '199', 'type': 'return_statement', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'final_resp'}
def get_locations(self, filter_to_my_group=False): resp = self._post('general-retrievelocations', 'locations') groups = {} if resp['groupinfo']: for group in resp['groupinfo']: groups[group['id']] = Group( name=group.get('name'), inventory_id=group.get('id') ) final_resp = [] if resp['data']: if filter_to_my_group: resp['data'] = {self.groupid: resp['data'][self.groupid]} for groupid, sublocation in resp['data'].items(): if type(sublocation) is dict: sublocation = [loc for _, loc in sublocation.items()] sublocation = flatten_list(sublocation) if type(sublocation) is list: sublocation = flatten_list(sublocation) for location in sublocation: group = groups[groupid] final_resp.append(Location( name=location.get('name'), inventory_id=location.get('id'), parent=location.get('parent'), group=group, barcode=location.get('barcode') )) return final_resp
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_image_url'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'dst_color'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'src_color'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '26', '35', '39', '159', '163', '456', '465']},{'id': '12', 'type': 'if_statement', 'children': ['13', '16']},{'id': '13', 'type': 'boolean_operator', 'children': ['14', '15'], 'value': 'and'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'src_color'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'dst_color'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'if_statement', 'children': ['18', '20']},{'id': '18', 'type': 'not_operator', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'Image'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'raise_statement', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'string', 'children': [], 'value': '"Images manipulation require PIL"'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '29', 'type': 'attribute', 'children': ['30', '34']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'StringValue'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '38', 'type': 'None', 'children': []},{'id': '39', 'type': 'if_statement', 'children': ['40', '44', '104']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'callable'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'STATIC_ROOT'},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'try_statement', 'children': ['46', '98']},{'id': '46', 'type': 'block', 'children': ['47', '61', '70', '86']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '52']},{'id': '49', 'type': 'pattern_list', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': '_file'},{'id': '51', 'type': 'identifier', 'children': [], 'value': '_storage'},{'id': '52', 'type': 'subscript', 'children': ['53', '60']},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'STATIC_ROOT'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '60', 'type': 'integer', 'children': [], 'value': '0'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'd_obj'},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': '_storage'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'modified_time'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': '_file'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'filetime'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'mktime'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'd_obj'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'timetuple'},{'id': '85', 'type': 'argument_list', 'children': []},{'id': '86', 'type': 'if_statement', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'dst_color'},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': '_storage'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': '_file'},{'id': '98', 'type': 'except_clause', 'children': ['99']},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'filetime'},{'id': '103', 'type': 'string', 'children': [], 'value': "'NA'"},{'id': '104', 'type': 'else_clause', 'children': ['105']},{'id': '105', 'type': 'block', 'children': ['106', '118']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': '_path'},{'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': 'os'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '115', 'type': 'argument_list', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'STATIC_ROOT'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '118', 'type': 'if_statement', 'children': ['119', '127', '153']},{'id': '119', 'type': 'call', 'children': ['120', '125']},{'id': '120', 'type': 'attribute', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': '_path'},{'id': '127', 'type': 'block', 'children': ['128', '142']},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'filetime'},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'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': 'getmtime'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': '_path'},{'id': '142', 'type': 'if_statement', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'dst_color'},{'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': 'path'},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '150', 'type': 'argument_list', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': '_path'},{'id': '152', 'type': 'string', 'children': [], 'value': "'rb'"},{'id': '153', 'type': 'else_clause', 'children': ['154']},{'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': 'filetime'},{'id': '158', 'type': 'string', 'children': [], 'value': "'NA'"},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'BASE_URL'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'STATIC_URL'},{'id': '163', 'type': 'if_statement', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '165', 'type': 'block', 'children': ['166', '197', '220', '252', '259', '295', '301', '313']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'src_color'},{'id': '169', 'type': 'conditional_expression', 'children': ['170', '192', '193'], 'value': 'if'},{'id': '170', 'type': 'call', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '172', 'type': 'generator_expression', 'children': ['173', '180']},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'round'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '180', 'type': 'for_in_clause', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '182', 'type': 'subscript', 'children': ['183', '189']},{'id': '183', 'type': 'attribute', 'children': ['184', '188']},{'id': '184', 'type': 'call', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'ColorValue'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'src_color'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '189', 'type': 'slice', 'children': ['190', '191']},{'id': '190', 'type': 'colon', 'children': []},{'id': '191', 'type': 'integer', 'children': [], 'value': '3'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'src_color'},{'id': '193', 'type': 'tuple', 'children': ['194', '195', '196']},{'id': '194', 'type': 'integer', 'children': [], 'value': '0'},{'id': '195', 'type': 'integer', 'children': [], 'value': '0'},{'id': '196', 'type': 'integer', 'children': [], 'value': '0'},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'dst_color'},{'id': '200', 'type': 'list_comprehension', 'children': ['201', '208']},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'round'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '208', 'type': 'for_in_clause', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '210', 'type': 'subscript', 'children': ['211', '217']},{'id': '211', 'type': 'attribute', 'children': ['212', '216']},{'id': '212', 'type': 'call', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'ColorValue'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'dst_color'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '217', 'type': 'slice', 'children': ['218', '219']},{'id': '218', 'type': 'colon', 'children': []},{'id': '219', 'type': 'integer', 'children': [], 'value': '3'},{'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': 'file_name'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'file_ext'},{'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': 'splitext'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'call', 'children': ['233', '249']},{'id': '233', 'type': 'attribute', 'children': ['234', '248']},{'id': '234', 'type': 'call', 'children': ['235', '245']},{'id': '235', 'type': 'attribute', 'children': ['236', '244']},{'id': '236', 'type': 'call', 'children': ['237', '242']},{'id': '237', 'type': 'attribute', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'normpath'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '245', 'type': 'argument_list', 'children': ['246', '247']},{'id': '246', 'type': 'string', 'children': [], 'value': "'\\\\'"},{'id': '247', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '249', 'type': 'argument_list', 'children': ['250', '251']},{'id': '250', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '251', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'assignment', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '255', 'type': 'tuple', 'children': ['256', '257', '258']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'filetime'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'src_color'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'dst_color'},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'assignment', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '262', 'type': 'binary_operator', 'children': ['263', '266'], 'value': '+'},{'id': '263', 'type': 'binary_operator', 'children': ['264', '265'], 'value': '+'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'file_name'},{'id': '265', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '266', 'type': 'call', 'children': ['267', '292']},{'id': '267', 'type': 'attribute', 'children': ['268', '291']},{'id': '268', 'type': 'call', 'children': ['269', '289']},{'id': '269', 'type': 'attribute', 'children': ['270', '288']},{'id': '270', 'type': 'call', 'children': ['271', '274']},{'id': '271', 'type': 'attribute', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'base64'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'urlsafe_b64encode'},{'id': '274', 'type': 'argument_list', 'children': ['275']},{'id': '275', 'type': 'call', 'children': ['276', '287']},{'id': '276', 'type': 'attribute', 'children': ['277', '286']},{'id': '277', 'type': 'call', 'children': ['278', '281']},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'hashlib'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'md5'},{'id': '281', 'type': 'argument_list', 'children': ['282']},{'id': '282', 'type': 'call', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'repr'},{'id': '284', 'type': 'argument_list', 'children': ['285']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'digest'},{'id': '287', 'type': 'argument_list', 'children': []},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'rstrip'},{'id': '289', 'type': 'argument_list', 'children': ['290']},{'id': '290', 'type': 'string', 'children': [], 'value': "'='"},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '292', 'type': 'argument_list', 'children': ['293', '294']},{'id': '293', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '294', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '295', 'type': 'expression_statement', 'children': ['296']},{'id': '296', 'type': 'assignment', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'asset_file'},{'id': '298', 'type': 'binary_operator', 'children': ['299', '300'], 'value': '+'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'file_ext'},{'id': '301', 'type': 'expression_statement', 'children': ['302']},{'id': '302', 'type': 'assignment', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'asset_path'},{'id': '304', 'type': 'call', 'children': ['305', '310']},{'id': '305', 'type': 'attribute', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '310', 'type': 'argument_list', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'ASSETS_ROOT'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'asset_file'},{'id': '313', 'type': 'if_statement', 'children': ['314', '322', '345']},{'id': '314', 'type': 'call', 'children': ['315', '320']},{'id': '315', 'type': 'attribute', 'children': ['316', '319']},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '320', 'type': 'argument_list', 'children': ['321']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'asset_path'},{'id': '322', 'type': 'block', 'children': ['323', '327', '331']},{'id': '323', 'type': 'expression_statement', 'children': ['324']},{'id': '324', 'type': 'assignment', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'asset_file'},{'id': '327', 'type': 'expression_statement', 'children': ['328']},{'id': '328', 'type': 'assignment', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'BASE_URL'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'ASSETS_URL'},{'id': '331', 'type': 'expression_statement', 'children': ['332']},{'id': '332', 'type': 'assignment', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'filetime'},{'id': '334', 'type': 'call', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '336', 'type': 'argument_list', 'children': ['337']},{'id': '337', 'type': 'call', 'children': ['338', '343']},{'id': '338', 'type': 'attribute', 'children': ['339', '342']},{'id': '339', 'type': 'attribute', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'getmtime'},{'id': '343', 'type': 'argument_list', 'children': ['344']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'asset_path'},{'id': '345', 'type': 'else_clause', 'children': ['346']},{'id': '346', 'type': 'block', 'children': ['347', '356', '365', '373', '429']},{'id': '347', 'type': 'expression_statement', 'children': ['348']},{'id': '348', 'type': 'assignment', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '350', 'type': 'call', 'children': ['351', '354']},{'id': '351', 'type': 'attribute', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'Image'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '354', 'type': 'argument_list', 'children': ['355']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '356', 'type': 'expression_statement', 'children': ['357']},{'id': '357', 'type': 'assignment', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '359', 'type': 'call', 'children': ['360', '363']},{'id': '360', 'type': 'attribute', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'convert'},{'id': '363', 'type': 'argument_list', 'children': ['364']},{'id': '364', 'type': 'string', 'children': [], 'value': '"RGBA"'},{'id': '365', 'type': 'expression_statement', 'children': ['366']},{'id': '366', 'type': 'assignment', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'pixdata'},{'id': '368', 'type': 'call', 'children': ['369', '372']},{'id': '369', 'type': 'attribute', 'children': ['370', '371']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'load'},{'id': '372', 'type': 'argument_list', 'children': []},{'id': '373', 'type': 'for_statement', 'children': ['374', '375', '383']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '375', 'type': 'call', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'xrange'},{'id': '377', 'type': 'argument_list', 'children': ['378']},{'id': '378', 'type': 'subscript', 'children': ['379', '382']},{'id': '379', 'type': 'attribute', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '382', 'type': 'integer', 'children': [], 'value': '1'},{'id': '383', 'type': 'block', 'children': ['384']},{'id': '384', 'type': 'for_statement', 'children': ['385', '386', '394']},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '386', 'type': 'call', 'children': ['387', '388']},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'xrange'},{'id': '388', 'type': 'argument_list', 'children': ['389']},{'id': '389', 'type': 'subscript', 'children': ['390', '393']},{'id': '390', 'type': 'attribute', 'children': ['391', '392']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '393', 'type': 'integer', 'children': [], 'value': '0'},{'id': '394', 'type': 'block', 'children': ['395']},{'id': '395', 'type': 'if_statement', 'children': ['396', '406']},{'id': '396', 'type': 'comparison_operator', 'children': ['397', '405'], 'value': '=='},{'id': '397', 'type': 'subscript', 'children': ['398', '402']},{'id': '398', 'type': 'subscript', 'children': ['399', '400', '401']},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'pixdata'},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '402', 'type': 'slice', 'children': ['403', '404']},{'id': '403', 'type': 'colon', 'children': []},{'id': '404', 'type': 'integer', 'children': [], 'value': '3'},{'id': '405', 'type': 'identifier', 'children': [], 'value': 'src_color'},{'id': '406', 'type': 'block', 'children': ['407', '422']},{'id': '407', 'type': 'expression_statement', 'children': ['408']},{'id': '408', 'type': 'assignment', 'children': ['409', '410']},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'new_color'},{'id': '410', 'type': 'call', 'children': ['411', '412']},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '412', 'type': 'argument_list', 'children': ['413']},{'id': '413', 'type': 'binary_operator', 'children': ['414', '415'], 'value': '+'},{'id': '414', 'type': 'identifier', 'children': [], 'value': 'dst_color'},{'id': '415', 'type': 'list', 'children': ['416'], 'value': '[pixdata[x, y][3]]'},{'id': '416', 'type': 'subscript', 'children': ['417', '421']},{'id': '417', 'type': 'subscript', 'children': ['418', '419', '420']},{'id': '418', 'type': 'identifier', 'children': [], 'value': 'pixdata'},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '421', 'type': 'integer', 'children': [], 'value': '3'},{'id': '422', 'type': 'expression_statement', 'children': ['423']},{'id': '423', 'type': 'assignment', 'children': ['424', '428']},{'id': '424', 'type': 'subscript', 'children': ['425', '426', '427']},{'id': '425', 'type': 'identifier', 'children': [], 'value': 'pixdata'},{'id': '426', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '427', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'new_color'},{'id': '429', 'type': 'try_statement', 'children': ['430', '446']},{'id': '430', 'type': 'block', 'children': ['431', '438', '442']},{'id': '431', 'type': 'expression_statement', 'children': ['432']},{'id': '432', 'type': 'call', 'children': ['433', '436']},{'id': '433', 'type': 'attribute', 'children': ['434', '435']},{'id': '434', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '435', 'type': 'identifier', 'children': [], 'value': 'save'},{'id': '436', 'type': 'argument_list', 'children': ['437']},{'id': '437', 'type': 'identifier', 'children': [], 'value': 'asset_path'},{'id': '438', 'type': 'expression_statement', 'children': ['439']},{'id': '439', 'type': 'assignment', 'children': ['440', '441']},{'id': '440', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '441', 'type': 'identifier', 'children': [], 'value': 'asset_file'},{'id': '442', 'type': 'expression_statement', 'children': ['443']},{'id': '443', 'type': 'assignment', 'children': ['444', '445']},{'id': '444', 'type': 'identifier', 'children': [], 'value': 'BASE_URL'},{'id': '445', 'type': 'identifier', 'children': [], 'value': 'ASSETS_URL'},{'id': '446', 'type': 'except_clause', 'children': ['447', '448']},{'id': '447', 'type': 'identifier', 'children': [], 'value': 'IOError'},{'id': '448', 'type': 'block', 'children': ['449']},{'id': '449', 'type': 'expression_statement', 'children': ['450']},{'id': '450', 'type': 'call', 'children': ['451', '454']},{'id': '451', 'type': 'attribute', 'children': ['452', '453']},{'id': '452', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '453', 'type': 'identifier', 'children': [], 'value': 'exception'},{'id': '454', 'type': 'argument_list', 'children': ['455']},{'id': '455', 'type': 'string', 'children': [], 'value': '"Error while saving image"'},{'id': '456', 'type': 'expression_statement', 'children': ['457']},{'id': '457', 'type': 'assignment', 'children': ['458', '459']},{'id': '458', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '459', 'type': 'binary_operator', 'children': ['460', '461'], 'value': '%'},{'id': '460', 'type': 'string', 'children': [], 'value': '\'url("%s%s?_=%s")\''},{'id': '461', 'type': 'tuple', 'children': ['462', '463', '464']},{'id': '462', 'type': 'identifier', 'children': [], 'value': 'BASE_URL'},{'id': '463', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '464', 'type': 'identifier', 'children': [], 'value': 'filetime'},{'id': '465', 'type': 'return_statement', 'children': ['466']},{'id': '466', 'type': 'call', 'children': ['467', '468']},{'id': '467', 'type': 'identifier', 'children': [], 'value': 'StringValue'},{'id': '468', 'type': 'argument_list', 'children': ['469']},{'id': '469', 'type': 'identifier', 'children': [], 'value': 'url'}
def _image_url(image, dst_color=None, src_color=None): if src_color and dst_color: if not Image: raise Exception("Images manipulation require PIL") file = StringValue(image).value path = None if callable(STATIC_ROOT): try: _file, _storage = list(STATIC_ROOT(file))[0] d_obj = _storage.modified_time(_file) filetime = int(time.mktime(d_obj.timetuple())) if dst_color: path = _storage.open(_file) except: filetime = 'NA' else: _path = os.path.join(STATIC_ROOT, file) if os.path.exists(_path): filetime = int(os.path.getmtime(_path)) if dst_color: path = open(_path, 'rb') else: filetime = 'NA' BASE_URL = STATIC_URL if path: src_color = tuple(int(round(c)) for c in ColorValue( src_color).value[:3]) if src_color else (0, 0, 0) dst_color = [int(round(c)) for c in ColorValue(dst_color).value[:3]] file_name, file_ext = os.path.splitext( os.path.normpath(file).replace('\\', '_').replace('/', '_')) key = (filetime, src_color, dst_color) key = file_name + '-' + base64.urlsafe_b64encode( hashlib.md5(repr(key)).digest()).rstrip('=').replace('-', '_') asset_file = key + file_ext asset_path = os.path.join(ASSETS_ROOT, asset_file) if os.path.exists(asset_path): file = asset_file BASE_URL = ASSETS_URL filetime = int(os.path.getmtime(asset_path)) else: image = Image.open(path) image = image.convert("RGBA") pixdata = image.load() for y in xrange(image.size[1]): for x in xrange(image.size[0]): if pixdata[x, y][:3] == src_color: new_color = tuple(dst_color + [pixdata[x, y][3]]) pixdata[x, y] = new_color try: image.save(asset_path) file = asset_file BASE_URL = ASSETS_URL except IOError: log.exception("Error while saving image") url = 'url("%s%s?_=%s")' % (BASE_URL, file, filetime) return StringValue(url)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'normalize_selectors'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': '_selectors'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'extra_selectors'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'extra_parents'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '23', '39', '55', '61', '168', '191', '198', '204', '227', '234', '259']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': '_selectors'},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_spaces_re'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'string', 'children': [], 'value': "' '"},{'id': '22', 'type': 'identifier', 'children': [], 'value': '_selectors'},{'id': '23', 'type': 'if_statement', 'children': ['24', '29']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'extra_selectors'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'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': 'extra_selectors'},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'extra_selectors'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'string', 'children': [], 'value': "','"},{'id': '39', 'type': 'if_statement', 'children': ['40', '45']},{'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': 'extra_parents'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'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': 'extra_parents'},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'extra_parents'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'string', 'children': [], 'value': "'&'"},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'parents'},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '60', 'type': 'argument_list', 'children': []},{'id': '61', 'type': 'if_statement', 'children': ['62', '65', '141']},{'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'in'},{'id': '63', 'type': 'string', 'children': [], 'value': "' extends '"},{'id': '64', 'type': 'identifier', 'children': [], 'value': '_selectors'},{'id': '65', 'type': 'block', 'children': ['66', '72']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'selectors'},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '71', 'type': 'argument_list', 'children': []},{'id': '72', 'type': 'for_statement', 'children': ['73', '74', '80']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': '_selectors'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'string', 'children': [], 'value': "','"},{'id': '80', 'type': 'block', 'children': ['81', '93', '101', '109', '116']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '87']},{'id': '83', 'type': 'pattern_list', 'children': ['84', '85', '86']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '85', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'partition'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'string', 'children': [], 'value': "' extends '"},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '100', 'type': 'argument_list', 'children': []},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '108', 'type': 'argument_list', 'children': []},{'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': 'selectors'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'parents'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '121', 'type': 'generator_expression', 'children': ['122', '127', '135']},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '126', 'type': 'argument_list', 'children': []},{'id': '127', 'type': 'for_in_clause', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'string', 'children': [], 'value': "'&'"},{'id': '135', 'type': 'if_clause', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '140', 'type': 'argument_list', 'children': []},{'id': '141', 'type': 'else_clause', 'children': ['142']},{'id': '142', 'type': 'block', 'children': ['143']},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'selectors'},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '148', 'type': 'generator_expression', 'children': ['149', '154', '162']},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '153', 'type': 'argument_list', 'children': []},{'id': '154', 'type': 'for_in_clause', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '156', 'type': 'call', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': '_selectors'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'string', 'children': [], 'value': "','"},{'id': '162', 'type': 'if_clause', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '167', 'type': 'argument_list', 'children': []},{'id': '168', 'type': 'if_statement', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'extra_selectors'},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'selectors'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '176', 'type': 'generator_expression', 'children': ['177', '182', '185']},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '181', 'type': 'argument_list', 'children': []},{'id': '182', 'type': 'for_in_clause', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'extra_selectors'},{'id': '185', 'type': 'if_clause', 'children': ['186']},{'id': '186', 'type': 'call', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '190', 'type': 'argument_list', 'children': []},{'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': 'selectors'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'discard'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'string', 'children': [], 'value': "''"},{'id': '198', 'type': 'if_statement', 'children': ['199', '201']},{'id': '199', 'type': 'not_operator', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'selectors'},{'id': '201', 'type': 'block', 'children': ['202']},{'id': '202', 'type': 'return_statement', 'children': ['203']},{'id': '203', 'type': 'string', 'children': [], 'value': "''"},{'id': '204', 'type': 'if_statement', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'extra_parents'},{'id': '206', 'type': 'block', 'children': ['207']},{'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': 'parents'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '212', 'type': 'generator_expression', 'children': ['213', '218', '221']},{'id': '213', 'type': 'call', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '217', 'type': 'argument_list', 'children': []},{'id': '218', 'type': 'for_in_clause', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'extra_parents'},{'id': '221', 'type': 'if_clause', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '226', 'type': 'argument_list', 'children': []},{'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': 'parents'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'discard'},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'string', 'children': [], 'value': "''"},{'id': '234', 'type': 'if_statement', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'parents'},{'id': '236', 'type': 'block', 'children': ['237']},{'id': '237', 'type': 'return_statement', 'children': ['238']},{'id': '238', 'type': 'binary_operator', 'children': ['239', '250'], 'value': '+'},{'id': '239', 'type': 'binary_operator', 'children': ['240', '249'], 'value': '+'},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'string', 'children': [], 'value': "','"},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'call', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'selectors'},{'id': '249', 'type': 'string', 'children': [], 'value': "' extends '"},{'id': '250', 'type': 'call', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'string', 'children': [], 'value': "'&'"},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '254', 'type': 'argument_list', 'children': ['255']},{'id': '255', 'type': 'call', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '257', 'type': 'argument_list', 'children': ['258']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'parents'},{'id': '259', 'type': 'return_statement', 'children': ['260']},{'id': '260', 'type': 'call', 'children': ['261', '264']},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'string', 'children': [], 'value': "','"},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '264', 'type': 'argument_list', 'children': ['265']},{'id': '265', 'type': 'call', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '267', 'type': 'argument_list', 'children': ['268']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'selectors'}
def normalize_selectors(self, _selectors, extra_selectors=None, extra_parents=None): _selectors = _spaces_re.sub(' ', _selectors) if isinstance(extra_selectors, basestring): extra_selectors = extra_selectors.split(',') if isinstance(extra_parents, basestring): extra_parents = extra_parents.split('&') parents = set() if ' extends ' in _selectors: selectors = set() for key in _selectors.split(','): child, _, parent = key.partition(' extends ') child = child.strip() parent = parent.strip() selectors.add(child) parents.update( s.strip() for s in parent.split('&') if s.strip()) else: selectors = set( s.strip() for s in _selectors.split(',') if s.strip()) if extra_selectors: selectors.update(s.strip() for s in extra_selectors if s.strip()) selectors.discard('') if not selectors: return '' if extra_parents: parents.update(s.strip() for s in extra_parents if s.strip()) parents.discard('') if parents: return ','.join(sorted(selectors)) + ' extends ' + '&'.join(sorted(parents)) return ','.join(sorted(selectors))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_properties'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11', '12', '13']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'p_selectors'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'p_parents'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'p_children'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'scope'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'media'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'c_lineno'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'c_property'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'c_codestr'},{'id': '14', 'type': 'block', 'children': ['15', '35', '56', '64', '81']},{'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': 'prop'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '20', 'type': 'subscript', 'children': ['21', '32']},{'id': '21', 'type': '()', 'children': ['22']},{'id': '22', 'type': 'binary_operator', 'children': ['23', '30'], 'value': '+'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': '_prop_split_re'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'c_property'},{'id': '29', 'type': 'integer', 'children': [], 'value': '1'},{'id': '30', 'type': 'list', 'children': ['31'], 'value': '[None]'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'slice', 'children': ['33', '34']},{'id': '33', 'type': 'colon', 'children': []},{'id': '34', 'type': 'integer', 'children': [], 'value': '2'},{'id': '35', 'type': 'try_statement', 'children': ['36', '49']},{'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': 'is_var'},{'id': '40', 'type': '()', 'children': ['41']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '48'], 'value': '=='},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'c_property'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '48', 'type': 'string', 'children': [], 'value': "'='"},{'id': '49', 'type': 'except_clause', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'is_var'},{'id': '55', 'type': 'False', 'children': []},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'strip'},{'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': 'prop'},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'do_glob_math'},{'id': '71', 'type': 'argument_list', 'children': ['72', '73', '76', '79', '80']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '73', 'type': 'subscript', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'CONTEXT'},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'OPTIONS'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '80', 'type': 'True', 'children': []},{'id': '81', 'type': 'if_statement', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '83', 'type': 'block', 'children': ['84', '111', '120']},{'id': '84', 'type': 'if_statement', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '86', 'type': 'block', 'children': ['87', '95']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'value'},{'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': 'value'},{'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': 'calculate'},{'id': '102', 'type': 'argument_list', 'children': ['103', '104', '107', '110']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '104', 'type': 'subscript', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'CONTEXT'},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'OPTIONS'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': '_prop'},{'id': '114', 'type': 'binary_operator', 'children': ['115', '119'], 'value': '+'},{'id': '115', 'type': '()', 'children': ['116']},{'id': '116', 'type': 'boolean_operator', 'children': ['117', '118'], 'value': 'or'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'scope'},{'id': '118', 'type': 'string', 'children': [], 'value': "''"},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '120', 'type': 'if_statement', 'children': ['121', '133', '259']},{'id': '121', 'type': 'boolean_operator', 'children': ['122', '123'], 'value': 'or'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'is_var'},{'id': '123', 'type': 'boolean_operator', 'children': ['124', '130'], 'value': 'and'},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'string', 'children': [], 'value': "'$'"},{'id': '130', 'type': 'comparison_operator', 'children': ['131', '132'], 'value': 'is'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '132', 'type': 'None', 'children': []},{'id': '133', 'type': 'block', 'children': ['134', '246']},{'id': '134', 'type': 'if_statement', 'children': ['135', '140', '179']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '137', 'type': 'argument_list', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'if_statement', 'children': ['142', '145']},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': 'in'},{'id': '143', 'type': 'string', 'children': [], 'value': "'!default'"},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '145', 'type': 'block', 'children': ['146']},{'id': '146', 'type': 'if_statement', 'children': ['147', '152', '157']},{'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': 'in'},{'id': '148', 'type': 'identifier', 'children': [], 'value': '_prop'},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'CONTEXT'},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '156', 'type': 'None', 'children': []},{'id': '157', 'type': 'else_clause', 'children': ['158']},{'id': '158', 'type': 'block', 'children': ['159']},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '162', 'type': 'call', 'children': ['163', '178']},{'id': '163', 'type': 'attribute', 'children': ['164', '177']},{'id': '164', 'type': 'call', 'children': ['165', '174']},{'id': '165', 'type': 'attribute', 'children': ['166', '173']},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '170', 'type': 'argument_list', 'children': ['171', '172']},{'id': '171', 'type': 'string', 'children': [], 'value': "'!default'"},{'id': '172', 'type': 'string', 'children': [], 'value': "''"},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '174', 'type': 'argument_list', 'children': ['175', '176']},{'id': '175', 'type': 'string', 'children': [], 'value': "' '"},{'id': '176', 'type': 'string', 'children': [], 'value': "' '"},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '178', 'type': 'argument_list', 'children': []},{'id': '179', 'type': 'elif_clause', 'children': ['180', '185']},{'id': '180', 'type': 'call', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '182', 'type': 'argument_list', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'ListValue'},{'id': '185', 'type': 'block', 'children': ['186', '193']},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'ListValue'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '193', 'type': 'for_statement', 'children': ['194', '197', '204']},{'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', '203']},{'id': '198', 'type': 'attribute', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '203', 'type': 'argument_list', 'children': []},{'id': '204', 'type': 'block', 'children': ['205']},{'id': '205', 'type': 'if_statement', 'children': ['206', '209']},{'id': '206', 'type': 'comparison_operator', 'children': ['207', '208'], 'value': '=='},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '208', 'type': 'string', 'children': [], 'value': "'!default'"},{'id': '209', 'type': 'block', 'children': ['210', '245']},{'id': '210', 'type': 'if_statement', 'children': ['211', '216', '221']},{'id': '211', 'type': 'comparison_operator', 'children': ['212', '213'], 'value': 'in'},{'id': '212', 'type': 'identifier', 'children': [], 'value': '_prop'},{'id': '213', 'type': 'subscript', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'CONTEXT'},{'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': 'value'},{'id': '220', 'type': 'None', 'children': []},{'id': '221', 'type': 'else_clause', 'children': ['222']},{'id': '222', 'type': 'block', 'children': ['223', '229']},{'id': '223', 'type': 'delete_statement', 'children': ['224']},{'id': '224', 'type': 'subscript', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'assignment', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '232', 'type': 'conditional_expression', 'children': ['233', '238', '244'], 'value': 'if'},{'id': '233', 'type': 'call', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '237', 'type': 'argument_list', 'children': []},{'id': '238', 'type': 'comparison_operator', 'children': ['239', '243'], 'value': '=='},{'id': '239', 'type': 'call', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '241', 'type': 'argument_list', 'children': ['242']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '243', 'type': 'integer', 'children': [], 'value': '1'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '245', 'type': 'break_statement', 'children': []},{'id': '246', 'type': 'if_statement', 'children': ['247', '250']},{'id': '247', 'type': 'comparison_operator', 'children': ['248', '249'], 'value': 'is'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '249', 'type': 'None', 'children': []},{'id': '250', 'type': 'block', 'children': ['251']},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'assignment', 'children': ['253', '258']},{'id': '253', 'type': 'subscript', 'children': ['254', '257']},{'id': '254', 'type': 'subscript', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'CONTEXT'},{'id': '257', 'type': 'identifier', 'children': [], 'value': '_prop'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '259', 'type': 'else_clause', 'children': ['260']},{'id': '260', 'type': 'block', 'children': ['261', '278']},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'assignment', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': '_prop'},{'id': '264', 'type': 'call', 'children': ['265', '268']},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'apply_vars'},{'id': '268', 'type': 'argument_list', 'children': ['269', '270', '273', '276', '277']},{'id': '269', 'type': 'identifier', 'children': [], 'value': '_prop'},{'id': '270', 'type': 'subscript', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'CONTEXT'},{'id': '273', 'type': 'subscript', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'OPTIONS'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '277', 'type': 'True', 'children': []},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'call', 'children': ['280', '285']},{'id': '280', 'type': 'attribute', 'children': ['281', '284']},{'id': '281', 'type': 'subscript', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'PROPERTIES'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '285', 'type': 'argument_list', 'children': ['286']},{'id': '286', 'type': 'tuple', 'children': ['287', '288', '289']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'c_lineno'},{'id': '288', 'type': 'identifier', 'children': [], 'value': '_prop'},{'id': '289', 'type': 'conditional_expression', 'children': ['290', '294', '297'], 'value': 'if'},{'id': '290', 'type': 'call', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'to_str'},{'id': '292', 'type': 'argument_list', 'children': ['293']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '294', 'type': 'comparison_operator', 'children': ['295', '296'], 'value': 'is'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '296', 'type': 'None', 'children': []},{'id': '297', 'type': 'None', 'children': []}
def _get_properties(self, rule, p_selectors, p_parents, p_children, scope, media, c_lineno, c_property, c_codestr): prop, value = (_prop_split_re.split(c_property, 1) + [None])[:2] try: is_var = (c_property[len(prop)] == '=') except IndexError: is_var = False prop = prop.strip() prop = self.do_glob_math( prop, rule[CONTEXT], rule[OPTIONS], rule, True) if prop: if value: value = value.strip() value = self.calculate( value, rule[CONTEXT], rule[OPTIONS], rule) _prop = (scope or '') + prop if is_var or prop.startswith('$') and value is not None: if isinstance(value, basestring): if '!default' in value: if _prop in rule[CONTEXT]: value = None else: value = value.replace( '!default', '').replace(' ', ' ').strip() elif isinstance(value, ListValue): value = ListValue(value) for k, v in value.value.items(): if v == '!default': if _prop in rule[CONTEXT]: value = None else: del value.value[k] value = value.first( ) if len(value) == 1 else value break if value is not None: rule[CONTEXT][_prop] = value else: _prop = self.apply_vars( _prop, rule[CONTEXT], rule[OPTIONS], rule, True) rule[PROPERTIES].append((c_lineno, _prop, to_str(value) if value is not None else None))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'ERROR', 'children': ['2', '299']},{'id': '2', 'type': 'function_definition', 'children': ['3', '4', '9']},{'id': '3', 'type': 'function_name', 'children': [], 'value': 'link_with_parents'},{'id': '4', 'type': 'parameters', 'children': ['5', '6', '7', '8']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'c_selectors'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'c_rules'},{'id': '9', 'type': 'block', 'children': ['10', '14', '192', '208']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'parent_found'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'for_statement', 'children': ['15', '18', '25']},{'id': '15', 'type': 'pattern_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'p_selectors'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'p_rules'},{'id': '18', 'type': 'call', 'children': ['19', '24']},{'id': '19', 'type': 'attribute', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'block', 'children': ['26', '38', '47', '53', '57']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '32']},{'id': '28', 'type': 'pattern_list', 'children': ['29', '30', '31']},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_p_selectors'},{'id': '30', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '31', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'p_selectors'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'partition'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'string', 'children': [], 'value': "' extends '"},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': '_p_selectors'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': '_p_selectors'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'string', 'children': [], 'value': "','"},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'new_selectors'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '52', 'type': 'argument_list', 'children': []},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '56', 'type': 'False', 'children': []},{'id': '57', 'type': 'for_statement', 'children': ['58', '59', '60']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'p_selector'},{'id': '59', 'type': 'identifier', 'children': [], 'value': '_p_selectors'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'if_statement', 'children': ['62', '65']},{'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'in'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'p_selector'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'for_statement', 'children': ['67', '68', '74']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'c_selector'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'c_selectors'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'string', 'children': [], 'value': "','"},{'id': '74', 'type': 'block', 'children': ['75', '83', '93', '112', '122', '143']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '80']},{'id': '77', 'type': 'pattern_list', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': '_c_selector'},{'id': '79', 'type': 'identifier', 'children': [], 'value': '_parent'},{'id': '80', 'type': 'expression_list', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'c_selector'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'lcp'},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'longest_common_prefix'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': '_c_selector'},{'id': '92', 'type': 'identifier', 'children': [], 'value': '_parent'},{'id': '93', 'type': 'if_statement', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'lcp'},{'id': '95', 'type': 'block', 'children': ['96', '104']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': '_c_selector'},{'id': '99', 'type': 'subscript', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': '_c_selector'},{'id': '101', 'type': 'slice', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'lcp'},{'id': '103', 'type': 'colon', 'children': []},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': '_parent'},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': '_parent'},{'id': '109', 'type': 'slice', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'lcp'},{'id': '111', 'type': 'colon', 'children': []},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'lcs'},{'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': 'longest_common_suffix'},{'id': '119', 'type': 'argument_list', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': '_c_selector'},{'id': '121', 'type': 'identifier', 'children': [], 'value': '_parent'},{'id': '122', 'type': 'if_statement', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'lcs'},{'id': '124', 'type': 'block', 'children': ['125', '134']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': '_c_selector'},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': '_c_selector'},{'id': '130', 'type': 'slice', 'children': ['131', '132']},{'id': '131', 'type': 'colon', 'children': []},{'id': '132', 'type': 'unary_operator', 'children': ['133'], 'value': '-'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'lcs'},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': '_parent'},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': '_parent'},{'id': '139', 'type': 'slice', 'children': ['140', '141']},{'id': '140', 'type': 'colon', 'children': []},{'id': '141', 'type': 'unary_operator', 'children': ['142'], 'value': '-'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'lcs'},{'id': '143', 'type': 'if_statement', 'children': ['144', '147', '180']},{'id': '144', 'type': 'boolean_operator', 'children': ['145', '146'], 'value': 'and'},{'id': '145', 'type': 'identifier', 'children': [], 'value': '_c_selector'},{'id': '146', 'type': 'identifier', 'children': [], 'value': '_parent'},{'id': '147', 'type': 'ERROR', 'children': ['148', '149', '152', '154', '165', '177']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'prev_symbol'},{'id': '149', 'type': 'ERROR', 'children': ['150', '151']},{'id': '150', 'type': 'ERROR', 'children': [], 'value': '?'},{'id': '151', 'type': 'ERROR', 'children': [], 'value': '!'},{'id': '152', 'type': 'list', 'children': ['153'], 'value': '[\n 0]'},{'id': '153', 'type': 'integer', 'children': [], 'value': '0'},{'id': '154', 'type': 'ERROR', 'children': ['155', '164']},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'string', 'children': [], 'value': "'\n post_symbol = r'"},{'id': '157', 'type': 'argument_list', 'children': ['158', '160']},{'id': '158', 'type': 'ERROR', 'children': ['159']},{'id': '159', 'type': 'ERROR', 'children': [], 'value': '?!'},{'id': '160', 'type': 'list', 'children': ['161'], 'value': '[-\\w]'},{'id': '161', 'type': 'unary_operator', 'children': ['162', '163'], 'value': '-'},{'id': '162', 'type': 'ERROR', 'children': [], 'value': '\\'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'new_parent'},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '169', 'type': 'argument_list', 'children': ['170', '175', '176']},{'id': '170', 'type': 'binary_operator', 'children': ['171', '174'], 'value': '+'},{'id': '171', 'type': 'binary_operator', 'children': ['172', '173'], 'value': '+'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'prev_symbol'},{'id': '173', 'type': 'identifier', 'children': [], 'value': '_parent'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'post_symbol'},{'id': '175', 'type': 'identifier', 'children': [], 'value': '_c_selector'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'p_selector'},{'id': '177', 'type': 'comparison_operator', 'children': ['178', '179'], 'value': '!='},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'p_selector'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'new_parent'},{'id': '180', 'type': 'block', 'children': ['181', '188']},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'new_selectors'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'new_parent'},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '191', 'type': 'True', 'children': []},{'id': '192', 'type': 'if_statement', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '194', 'type': 'block', 'children': ['195', '201']},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'parent_found'},{'id': '198', 'type': 'boolean_operator', 'children': ['199', '200'], 'value': 'or'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'parent_found'},{'id': '200', 'type': 'list', 'children': [], 'value': '[]'},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'call', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'parent_found'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'p_rules'},{'id': '208', 'type': 'if_statement', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'new_selectors'},{'id': '210', 'type': 'block', 'children': ['211', '221', '253', '259', '280']},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'new_selectors'},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'normalize_selectors'},{'id': '218', 'type': 'argument_list', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'p_selectors'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'new_selectors'},{'id': '221', 'type': 'if_statement', 'children': ['222', '225']},{'id': '222', 'type': 'comparison_operator', 'children': ['223', '224'], 'value': '!='},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'new_selectors'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'p_selectors'},{'id': '225', 'type': 'block', 'children': ['226', '232', '242']},{'id': '226', 'type': 'delete_statement', 'children': ['227']},{'id': '227', 'type': 'subscript', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'p_selectors'},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'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': 'self'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '239', 'type': 'argument_list', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'new_selectors'},{'id': '241', 'type': 'list', 'children': [], 'value': '[]'},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'call', 'children': ['244', '251']},{'id': '244', 'type': 'attribute', 'children': ['245', '250']},{'id': '245', 'type': 'subscript', 'children': ['246', '249']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'new_selectors'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '251', 'type': 'argument_list', 'children': ['252']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'p_rules'},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'assignment', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'deps'},{'id': '256', 'type': 'call', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '258', 'type': 'argument_list', 'children': []},{'id': '259', 'type': 'for_statement', 'children': ['260', '261', '264']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'c_rule'},{'id': '261', 'type': 'boolean_operator', 'children': ['262', '263'], 'value': 'or'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'c_rules'},{'id': '263', 'type': 'list', 'children': [], 'value': '[]'},{'id': '264', 'type': 'block', 'children': ['265', '271']},{'id': '265', 'type': 'expression_statement', 'children': ['266']},{'id': '266', 'type': 'assignment', 'children': ['267', '270']},{'id': '267', 'type': 'subscript', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'c_rule'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'SELECTORS'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'c_selectors'},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'call', 'children': ['273', '276']},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'deps'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '276', 'type': 'argument_list', 'children': ['277']},{'id': '277', 'type': 'subscript', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'c_rule'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'POSITION'},{'id': '280', 'type': 'for_statement', 'children': ['281', '282', '283']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'p_rule'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'p_rules'},{'id': '283', 'type': 'block', 'children': ['284', '290']},{'id': '284', 'type': 'expression_statement', 'children': ['285']},{'id': '285', 'type': 'assignment', 'children': ['286', '289']},{'id': '286', 'type': 'subscript', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'p_rule'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'SELECTORS'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'new_selectors'},{'id': '290', 'type': 'expression_statement', 'children': ['291']},{'id': '291', 'type': 'call', 'children': ['292', '297']},{'id': '292', 'type': 'attribute', 'children': ['293', '296']},{'id': '293', 'type': 'subscript', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'p_rule'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'DEPS'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '297', 'type': 'argument_list', 'children': ['298']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'deps'},{'id': '299', 'type': 'return_statement', 'children': ['300']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'parent_found'}
def link_with_parents(self, parent, c_selectors, c_rules): parent_found = None for p_selectors, p_rules in self.parts.items(): _p_selectors, _, _ = p_selectors.partition(' extends ') _p_selectors = _p_selectors.split(',') new_selectors = set() found = False for p_selector in _p_selectors: if parent in p_selector: for c_selector in c_selectors.split(','): _c_selector, _parent = c_selector, parent lcp = self.longest_common_prefix(_c_selector, _parent) if lcp: _c_selector = _c_selector[lcp:] _parent = _parent[lcp:] lcs = self.longest_common_suffix(_c_selector, _parent) if lcs: _c_selector = _c_selector[:-lcs] _parent = _parent[:-lcs] if _c_selector and _parent: prev_symbol = '(?<![ 0] in (' post_symbol = r'(?![-\w])' new_parent = re.sub(prev_symbol + _parent + post_symbol, _c_selector, p_selector) if p_selector != new_parent: new_selectors.add(new_parent) found = True if found: parent_found = parent_found or [] parent_found.extend(p_rules) if new_selectors: new_selectors = self.normalize_selectors( p_selectors, new_selectors) if new_selectors != p_selectors: del self.parts[p_selectors] self.parts.setdefault(new_selectors, []) self.parts[new_selectors].extend(p_rules) deps = set() for c_rule in c_rules or []: c_rule[SELECTORS] = c_selectors deps.add(c_rule[POSITION]) for p_rule in p_rules: p_rule[SELECTORS] = new_selectors p_rule[DEPS].update( deps) return parent_found
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_extends'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '87', '91', '95']},{'id': '6', 'type': 'for_statement', 'children': ['7', '10', '17']},{'id': '7', 'type': 'pattern_list', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': '_selectors'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'rules'},{'id': '10', 'type': 'call', 'children': ['11', '16']},{'id': '11', 'type': 'attribute', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'if_statement', 'children': ['19', '22']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'in'},{'id': '20', 'type': 'string', 'children': [], 'value': "' extends '"},{'id': '21', 'type': 'identifier', 'children': [], 'value': '_selectors'},{'id': '22', 'type': 'block', 'children': ['23', '35', '44', '50']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '29']},{'id': '25', 'type': 'pattern_list', 'children': ['26', '27', '28']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'selectors'},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': '_selectors'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'partition'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'string', 'children': [], 'value': "' extends '"},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'parents'},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'string', 'children': [], 'value': "'&'"},{'id': '44', 'type': 'delete_statement', 'children': ['45']},{'id': '45', 'type': 'subscript', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '49', 'type': 'identifier', 'children': [], 'value': '_selectors'},{'id': '50', 'type': 'for_statement', 'children': ['51', '52', '53']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'parents'},{'id': '53', 'type': 'block', 'children': ['54', '62', '72', '83']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'new_selectors'},{'id': '57', 'type': 'binary_operator', 'children': ['58', '61'], 'value': '+'},{'id': '58', 'type': 'binary_operator', 'children': ['59', '60'], 'value': '+'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'selectors'},{'id': '60', 'type': 'string', 'children': [], 'value': "' extends '"},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '69']},{'id': '64', 'type': 'attribute', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'new_selectors'},{'id': '71', 'type': 'list', 'children': [], 'value': '[]'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '81']},{'id': '74', 'type': 'attribute', 'children': ['75', '80']},{'id': '75', 'type': 'subscript', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'new_selectors'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'rules'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'rules'},{'id': '86', 'type': 'list', 'children': [], 'value': '[]'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'cnt'},{'id': '90', 'type': 'integer', 'children': [], 'value': '0'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'parents_left'},{'id': '94', 'type': 'True', 'children': []},{'id': '95', 'type': 'while_statement', 'children': ['96', '101']},{'id': '96', 'type': 'boolean_operator', 'children': ['97', '98'], 'value': 'and'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'parents_left'},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': '<'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'cnt'},{'id': '100', 'type': 'integer', 'children': [], 'value': '10'},{'id': '101', 'type': 'block', 'children': ['102', '106', '110']},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'augmented_assignment', 'children': ['104', '105'], 'value': '+='},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'cnt'},{'id': '105', 'type': 'integer', 'children': [], 'value': '1'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'parents_left'},{'id': '109', 'type': 'False', 'children': []},{'id': '110', 'type': 'for_statement', 'children': ['111', '112', '119']},{'id': '111', 'type': 'identifier', 'children': [], 'value': '_selectors'},{'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': 'self'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '118', 'type': 'argument_list', 'children': []},{'id': '119', 'type': 'block', 'children': ['120', '132']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '126']},{'id': '122', 'type': 'pattern_list', 'children': ['123', '124', '125']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'selectors'},{'id': '124', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': '_selectors'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'partition'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'string', 'children': [], 'value': "' extends '"},{'id': '132', 'type': 'if_statement', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '134', 'type': 'block', 'children': ['135', '139', '147', '155', '161', '171', '182', '193']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'parents_left'},{'id': '138', 'type': 'True', 'children': []},{'id': '139', 'type': 'if_statement', 'children': ['140', '145']},{'id': '140', 'type': 'comparison_operator', 'children': ['141', '142'], 'value': 'not'},{'id': '141', 'type': 'identifier', 'children': [], 'value': '_selectors'},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '145', 'type': 'block', 'children': ['146']},{'id': '146', 'type': 'continue_statement', 'children': []},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'rules'},{'id': '150', 'type': 'subscript', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '154', 'type': 'identifier', 'children': [], 'value': '_selectors'},{'id': '155', 'type': 'delete_statement', 'children': ['156']},{'id': '156', 'type': 'subscript', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '160', 'type': 'identifier', 'children': [], 'value': '_selectors'},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'call', 'children': ['163', '168']},{'id': '163', 'type': 'attribute', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '168', 'type': 'argument_list', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'selectors'},{'id': '170', 'type': 'list', 'children': [], 'value': '[]'},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '180']},{'id': '173', 'type': 'attribute', 'children': ['174', '179']},{'id': '174', 'type': 'subscript', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'selectors'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'rules'},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'parents'},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'link_with_parents'},{'id': '189', 'type': 'argument_list', 'children': ['190', '191', '192']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'selectors'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'rules'},{'id': '193', 'type': 'if_statement', 'children': ['194', '197', '206']},{'id': '194', 'type': 'comparison_operator', 'children': ['195', '196'], 'value': 'is'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'parents'},{'id': '196', 'type': 'None', 'children': []},{'id': '197', 'type': 'block', 'children': ['198']},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '203', 'type': 'argument_list', 'children': ['204', '205']},{'id': '204', 'type': 'string', 'children': [], 'value': '"Parent rule not found: %s"'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '206', 'type': 'else_clause', 'children': ['207']},{'id': '207', 'type': 'block', 'children': ['208', '212', '216', '238']},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'assignment', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'new_context'},{'id': '211', 'type': 'dictionary', 'children': []},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'new_options'},{'id': '215', 'type': 'dictionary', 'children': []},{'id': '216', 'type': 'for_statement', 'children': ['217', '218', '219']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'parents'},{'id': '219', 'type': 'block', 'children': ['220', '229']},{'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': 'new_context'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'subscript', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'CONTEXT'},{'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': 'new_options'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'subscript', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'OPTIONS'},{'id': '238', 'type': 'for_statement', 'children': ['239', '240', '241']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'rules'},{'id': '241', 'type': 'block', 'children': ['242', '250', '259', '265', '273', '282']},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'assignment', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': '_new_context'},{'id': '245', 'type': 'call', 'children': ['246', '249']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'new_context'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '249', 'type': 'argument_list', 'children': []},{'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': '_new_context'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'subscript', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'CONTEXT'},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'assignment', 'children': ['261', '264']},{'id': '261', 'type': 'subscript', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'CONTEXT'},{'id': '264', 'type': 'identifier', 'children': [], 'value': '_new_context'},{'id': '265', 'type': 'expression_statement', 'children': ['266']},{'id': '266', 'type': 'assignment', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': '_new_options'},{'id': '268', 'type': 'call', 'children': ['269', '272']},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'new_options'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '272', 'type': 'argument_list', 'children': []},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'call', 'children': ['275', '278']},{'id': '275', 'type': 'attribute', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': '_new_options'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '278', 'type': 'argument_list', 'children': ['279']},{'id': '279', 'type': 'subscript', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'OPTIONS'},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'assignment', 'children': ['284', '287']},{'id': '284', 'type': 'subscript', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'OPTIONS'},{'id': '287', 'type': 'identifier', 'children': [], 'value': '_new_options'}
def parse_extends(self): for _selectors, rules in self.parts.items(): if ' extends ' in _selectors: selectors, _, parent = _selectors.partition(' extends ') parents = parent.split('&') del self.parts[_selectors] for parent in parents: new_selectors = selectors + ' extends ' + parent self.parts.setdefault(new_selectors, []) self.parts[new_selectors].extend(rules) rules = [] cnt = 0 parents_left = True while parents_left and cnt < 10: cnt += 1 parents_left = False for _selectors in self.parts.keys(): selectors, _, parent = _selectors.partition(' extends ') if parent: parents_left = True if _selectors not in self.parts: continue rules = self.parts[_selectors] del self.parts[_selectors] self.parts.setdefault(selectors, []) self.parts[selectors].extend(rules) parents = self.link_with_parents(parent, selectors, rules) if parents is None: log.warn("Parent rule not found: %s", parent) else: new_context = {} new_options = {} for parent in parents: new_context.update(parent[CONTEXT]) new_options.update(parent[OPTIONS]) for rule in rules: _new_context = new_context.copy() _new_context.update(rule[CONTEXT]) rule[CONTEXT] = _new_context _new_options = new_options.copy() _new_options.update(rule[OPTIONS]) rule[OPTIONS] = _new_options
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'scan'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'restrict'},{'id': '6', 'type': 'block', 'children': ['7', '189']},{'id': '7', 'type': 'while_statement', 'children': ['8', '9']},{'id': '8', 'type': 'True', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '14', '18', '74', '105']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'best_pat'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'best_pat_len'},{'id': '17', 'type': 'integer', 'children': [], 'value': '0'},{'id': '18', 'type': 'for_statement', 'children': ['19', '22', '25']},{'id': '19', 'type': 'pattern_list', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'regexp'},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'patterns'},{'id': '25', 'type': 'block', 'children': ['26', '40', '54']},{'id': '26', 'type': 'if_statement', 'children': ['27', '38']},{'id': '27', 'type': 'boolean_operator', 'children': ['28', '33'], 'value': 'and'},{'id': '28', 'type': 'boolean_operator', 'children': ['29', '30'], 'value': 'and'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'restrict'},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': 'not'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'restrict'},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': 'not'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'ignore'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'continue_statement', 'children': []},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'regexp'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '47', 'type': 'argument_list', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'input'},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '54', 'type': 'if_statement', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '56', 'type': 'block', 'children': ['57', '61', '73']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'best_pat'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'best_pat_len'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'integer', 'children': [], 'value': '0'},{'id': '73', 'type': 'break_statement', 'children': []},{'id': '74', 'type': 'if_statement', 'children': ['75', '78']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'is'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'best_pat'},{'id': '77', 'type': 'None', 'children': []},{'id': '78', 'type': 'block', 'children': ['79', '83', '97']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '82', 'type': 'string', 'children': [], 'value': '"Bad Token"'},{'id': '83', 'type': 'if_statement', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'restrict'},{'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': 'msg'},{'id': '89', 'type': 'binary_operator', 'children': ['90', '91'], 'value': '+'},{'id': '90', 'type': 'string', 'children': [], 'value': '"Trying to find one of "'},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'string', 'children': [], 'value': '", "'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'restrict'},{'id': '97', 'type': 'raise_statement', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'SyntaxError'},{'id': '100', 'type': 'argument_list', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '105', 'type': 'if_statement', 'children': ['106', '111', '118']},{'id': '106', 'type': 'comparison_operator', 'children': ['107', '108'], 'value': 'in'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'best_pat'},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'ignore'},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'augmented_assignment', 'children': ['114', '117'], 'value': '+='},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'best_pat_len'},{'id': '118', 'type': 'else_clause', 'children': ['119']},{'id': '119', 'type': 'block', 'children': ['120', '128', '147', '153', '188']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'end_pos'},{'id': '123', 'type': 'binary_operator', 'children': ['124', '127'], 'value': '+'},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'best_pat_len'},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '131', 'type': 'tuple', 'children': ['132', '135', '136', '137']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'end_pos'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'best_pat'},{'id': '137', 'type': 'subscript', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'input'},{'id': '141', 'type': 'slice', 'children': ['142', '145', '146']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '145', 'type': 'colon', 'children': []},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'end_pos'},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'end_pos'},{'id': '153', 'type': 'if_statement', 'children': ['154', '167']},{'id': '154', 'type': 'boolean_operator', 'children': ['155', '159'], 'value': 'or'},{'id': '155', 'type': 'not_operator', 'children': ['156']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '159', 'type': 'comparison_operator', 'children': ['160', '161'], 'value': '!='},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '161', 'type': 'subscript', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '165', 'type': 'unary_operator', 'children': ['166'], 'value': '-'},{'id': '166', 'type': 'integer', 'children': [], 'value': '1'},{'id': '167', 'type': 'block', 'children': ['168', '177', '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': 'tokens'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '177', 'type': 'expression_statement', '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': 'self'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'restrictions'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'restrict'},{'id': '186', 'type': 'return_statement', 'children': ['187']},{'id': '187', 'type': 'integer', 'children': [], 'value': '1'},{'id': '188', 'type': 'break_statement', 'children': []},{'id': '189', 'type': 'return_statement', 'children': ['190']},{'id': '190', 'type': 'integer', 'children': [], 'value': '0'}
def scan(self, restrict): while True: best_pat = None best_pat_len = 0 for p, regexp in self.patterns: if restrict and p not in restrict and p not in self.ignore: continue m = regexp.match(self.input, self.pos) if m: best_pat = p best_pat_len = len(m.group(0)) break if best_pat is None: msg = "Bad Token" if restrict: msg = "Trying to find one of " + ", ".join(restrict) raise SyntaxError(self.pos, msg) if best_pat in self.ignore: self.pos += best_pat_len else: end_pos = self.pos + best_pat_len token = ( self.pos, end_pos, best_pat, self.input[self.pos:end_pos] ) self.pos = end_pos if not self.tokens or token != self.tokens[-1]: self.tokens.append(token) self.restrictions.append(restrict) return 1 break return 0
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'read_form_data'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '18', '24']},{'id': '6', 'type': 'if_statement', 'children': ['7', '10']},{'id': '7', 'type': 'attribute', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'processed_data'},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'raise_statement', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'AlreadyProcessed'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'string', 'children': [], 'value': "'The data has already been processed for this form'"},{'id': '18', 'type': 'if_statement', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'readonly'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'return_statement', 'children': []},{'id': '24', 'type': 'if_statement', 'children': ['25', '32']},{'id': '25', 'type': 'comparison_operator', 'children': ['26', '29'], 'value': '=='},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '32', 'type': 'block', 'children': ['33', '54']},{'id': '33', 'type': 'if_statement', 'children': ['34', '39', '46']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '38'], 'value': '=='},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '38', 'type': 'string', 'children': [], 'value': "'POST'"},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '46', 'type': 'else_clause', 'children': ['47']},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '54', 'type': 'if_statement', 'children': ['55', '60']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '59'], 'value': 'in'},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'submitted_hidden_input_name'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '60', 'type': 'block', 'children': ['61', '67']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'processed_data'},{'id': '66', 'type': 'True', 'children': []},{'id': '67', 'type': 'for_statement', 'children': ['68', '69', '72']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'all_fields'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'if_statement', 'children': ['74', '77', '79']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'readonly'},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'pass_statement', 'children': []},{'id': '79', 'type': 'else_clause', 'children': ['80']},{'id': '80', 'type': 'block', 'children': ['81', '88']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'extract_value'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '88', 'type': 'if_statement', 'children': ['89', '95']},{'id': '89', 'type': 'not_operator', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'validate'},{'id': '94', 'type': 'argument_list', 'children': []},{'id': '95', 'type': 'block', 'children': ['96', '111']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'binary_operator', 'children': ['103', '104'], 'value': '%'},{'id': '103', 'type': 'string', 'children': [], 'value': "'Validation error in field \\'%s\\': %s'"},{'id': '104', 'type': 'tuple', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'has_errors'},{'id': '116', 'type': 'True', 'children': []}
def read_form_data(self): if self.processed_data: raise exceptions.AlreadyProcessed('The data has already been processed for this form') if self.readonly: return if request.method == self.method: if self.method == 'POST': data = request.form else: data = request.args if self.submitted_hidden_input_name in data: self.processed_data = True for field in self.all_fields: if field.readonly: pass else: field.extract_value(data) if not field.validate(): log.debug('Validation error in field \'%s\': %s' % (field.name, field.error)) self.has_errors = True
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_imm_trans_setattr'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '7', 'type': 'block', 'children': ['8', '10', '17', '27']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'string', 'children': [], 'value': "'''\n An immutable's transient setattr allows params to be set, and runs checks as they are.\n '''"},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': '_imm_param_data'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'object'},{'id': '23', 'type': 'identifier', 'children': [], 'value': '__getattribute__'},{'id': '24', 'type': 'argument_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'string', 'children': [], 'value': "'__dict__'"},{'id': '27', 'type': 'if_statement', 'children': ['28', '31', '166']},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'in'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '31', 'type': 'block', 'children': ['32', '43', '55', '59', '65', '86']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '40']},{'id': '34', 'type': 'tuple_pattern', 'children': ['35', '36', '37', '38', '39']},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'tx_fn'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'arg_lists'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'check_fns'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'deps'},{'id': '40', 'type': 'subscript', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '46', 'type': 'conditional_expression', 'children': ['47', '48', '51'], 'value': 'if'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': 'is'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'tx_fn'},{'id': '50', 'type': 'None', 'children': []},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'tx_fn'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'old_deps'},{'id': '58', 'type': 'dictionary', 'children': []},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'orig_value'},{'id': '62', 'type': 'subscript', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '65', 'type': 'for_statement', 'children': ['66', '67', '68']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'dep'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'deps'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'if_statement', 'children': ['70', '73']},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': 'in'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'dep'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '73', 'type': 'block', 'children': ['74', '82']},{'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': 'old_deps'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'dep'},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'dep'},{'id': '82', 'type': 'delete_statement', 'children': ['83']},{'id': '83', 'type': 'subscript', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'dep'},{'id': '86', 'type': 'try_statement', 'children': ['87', '138']},{'id': '87', 'type': 'block', 'children': ['88', '94', '134']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '93']},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '94', 'type': 'for_statement', 'children': ['95', '98', '103']},{'id': '95', 'type': 'tuple_pattern', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'check_fn'},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '100', 'type': 'argument_list', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'arg_lists'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'check_fns'},{'id': '103', 'type': 'block', 'children': ['104']},{'id': '104', 'type': 'if_statement', 'children': ['105', '119']},{'id': '105', 'type': 'not_operator', 'children': ['106']},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'check_fn'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'list_splat', 'children': ['110']},{'id': '110', 'type': 'list_comprehension', 'children': ['111', '116']},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '113', 'type': 'argument_list', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '116', 'type': 'for_in_clause', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '119', 'type': 'block', 'children': ['120']},{'id': '120', 'type': 'raise_statement', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'binary_operator', 'children': ['125', '129'], 'value': '%'},{'id': '125', 'type': '()', 'children': ['126']},{'id': '126', 'type': 'binary_operator', 'children': ['127', '128'], 'value': '+'},{'id': '127', 'type': 'string', 'children': [], 'value': "'Changing value of immutable attribute \\'%s\\''"},{'id': '128', 'type': 'string', 'children': [], 'value': "' caused validation failure: %s'"},{'id': '129', 'type': 'tuple', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '131', 'type': 'tuple', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'check_fn'},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'old_deps'},{'id': '137', 'type': 'None', 'children': []},{'id': '138', 'type': 'finally_clause', 'children': ['139']},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'if_statement', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'old_deps'},{'id': '142', 'type': 'block', 'children': ['143', '160']},{'id': '143', 'type': 'for_statement', 'children': ['144', '147', '153']},{'id': '144', 'type': 'tuple_pattern', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'dep'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'old_deps'},{'id': '153', 'type': 'block', 'children': ['154']},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '159']},{'id': '156', 'type': 'subscript', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'dep'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '165']},{'id': '162', 'type': 'subscript', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'orig_value'},{'id': '166', 'type': 'else_clause', 'children': ['167']},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'raise_statement', 'children': ['169']},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'binary_operator', 'children': ['173', '174'], 'value': '%'},{'id': '173', 'type': 'string', 'children': [], 'value': "'Attempt to change non-parameter member \\'%s\\' of transient immutable'"},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'name'}
def _imm_trans_setattr(self, name, value): ''' An immutable's transient setattr allows params to be set, and runs checks as they are. ''' params = _imm_param_data(self) dd = object.__getattribute__(self, '__dict__') if name in params: (_, tx_fn, arg_lists, check_fns, deps) = params[name] value = value if tx_fn is None else tx_fn(value) old_deps = {} orig_value = dd[name] for dep in deps: if dep in dd: old_deps[dep] = dd[dep] del dd[dep] try: dd[name] = value for (args, check_fn) in zip(arg_lists, check_fns): if not check_fn(*[getattr(self, arg) for arg in args]): raise RuntimeError( ('Changing value of immutable attribute \'%s\'' + ' caused validation failure: %s') % (name, (args, check_fn))) old_deps = None finally: if old_deps: for (dep,val) in six.iteritems(old_deps): dd[dep] = val dd[name] = orig_value else: raise TypeError( 'Attempt to change non-parameter member \'%s\' of transient immutable' % name)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'verify_consistency'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'predictions'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'proba'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'opt_class'},{'id': '8', 'type': 'block', 'children': ['9', '25', '40', '55', '70', '85', '100', '115', '132', '149', '207']},{'id': '9', 'type': 'if_statement', 'children': ['10', '17']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '14'], 'value': '!='},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'predictions'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'raise_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'binary_operator', 'children': ['23', '24'], 'value': '+'},{'id': '23', 'type': 'string', 'children': [], 'value': '"predictions and scores arrays have inconsistent "'},{'id': '24', 'type': 'string', 'children': [], 'value': '"dimensions."'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'n_class'},{'id': '28', 'type': 'conditional_expression', 'children': ['29', '34', '39'], 'value': 'if'},{'id': '29', 'type': 'subscript', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '33', 'type': 'integer', 'children': [], 'value': '1'},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '38'], 'value': '>'},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '38', 'type': 'integer', 'children': [], 'value': '1'},{'id': '39', 'type': 'integer', 'children': [], 'value': '1'},{'id': '40', 'type': 'if_statement', 'children': ['41', '44']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'is'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'proba'},{'id': '43', 'type': 'None', 'children': []},{'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': 'proba'},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'repeat'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54']},{'id': '53', 'type': 'False', 'children': []},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'n_class'},{'id': '55', 'type': 'if_statement', 'children': ['56', '59']},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'is'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'opt_class'},{'id': '58', 'type': 'None', 'children': []},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'opt_class'},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'repeat'},{'id': '67', 'type': 'argument_list', 'children': ['68', '69']},{'id': '68', 'type': 'True', 'children': []},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'n_class'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'proba'},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '77', 'type': 'argument_list', 'children': ['78', '79', '82']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'proba'},{'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'ndmin'},{'id': '84', 'type': 'integer', 'children': [], 'value': '1'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'opt_class'},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '92', 'type': 'argument_list', 'children': ['93', '94', '97']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'opt_class'},{'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'ndmin'},{'id': '99', 'type': 'integer', 'children': [], 'value': '1'},{'id': '100', 'type': 'if_statement', 'children': ['101', '109']},{'id': '101', 'type': 'comparison_operator', 'children': ['102', '108'], 'value': '<'},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'opt_class'},{'id': '108', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'ValueError'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'string', 'children': [], 'value': '"opt_class should contain at least one True value."'},{'id': '115', 'type': 'if_statement', 'children': ['116', '126']},{'id': '116', 'type': 'comparison_operator', 'children': ['117', '122'], 'value': '!='},{'id': '117', 'type': 'subscript', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'predictions'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '121', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'proba'},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'raise_statement', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'string', 'children': [], 'value': '"mismatch in shape of proba and predictions."'},{'id': '132', 'type': 'if_statement', 'children': ['133', '143']},{'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': 'predictions'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '138', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'opt_class'},{'id': '143', 'type': 'block', 'children': ['144']},{'id': '144', 'type': 'raise_statement', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'string', 'children': [], 'value': '"mismatch in shape of opt_class and predictions."'},{'id': '149', 'type': 'for_statement', 'children': ['150', '151', '155']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'n_class'},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'if_statement', 'children': ['157', '186']},{'id': '157', 'type': '()', 'children': ['158']},{'id': '158', 'type': 'boolean_operator', 'children': ['159', '183'], 'value': 'and'},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'any'},{'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': 'np'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'logical_or'},{'id': '168', 'type': 'argument_list', 'children': ['169', '176']},{'id': '169', 'type': 'comparison_operator', 'children': ['170', '175'], 'value': '<'},{'id': '170', 'type': 'subscript', 'children': ['171', '172', '174']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '172', 'type': 'slice', 'children': ['173']},{'id': '173', 'type': 'colon', 'children': []},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '175', 'type': 'integer', 'children': [], 'value': '0'},{'id': '176', 'type': 'comparison_operator', 'children': ['177', '182'], 'value': '>'},{'id': '177', 'type': 'subscript', 'children': ['178', '179', '181']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '179', 'type': 'slice', 'children': ['180']},{'id': '180', 'type': 'colon', 'children': []},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '182', 'type': 'integer', 'children': [], 'value': '1'},{'id': '183', 'type': 'subscript', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'proba'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '186', 'type': 'block', 'children': ['187', '201']},{'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': 'warnings'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'binary_operator', 'children': ['194', '195'], 'value': '+'},{'id': '194', 'type': 'string', 'children': [], 'value': '"scores fall outside the [0,1] interval for "'},{'id': '195', 'type': 'call', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'string', 'children': [], 'value': '"classifier {}. Setting proba[m]=False."'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '206']},{'id': '203', 'type': 'subscript', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'proba'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '206', 'type': 'False', 'children': []},{'id': '207', 'type': 'return_statement', 'children': ['208']},{'id': '208', 'type': 'expression_list', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'proba'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'opt_class'}
def verify_consistency(predictions, scores, proba, opt_class): if predictions.shape != scores.shape: raise ValueError("predictions and scores arrays have inconsistent " + "dimensions.") n_class = scores.shape[1] if scores.ndim > 1 else 1 if proba is None: proba = np.repeat(False, n_class) if opt_class is None: opt_class = np.repeat(True, n_class) proba = np.array(proba, dtype=bool, ndmin=1) opt_class = np.array(opt_class, dtype=bool, ndmin=1) if np.sum(opt_class) < 1: raise ValueError("opt_class should contain at least one True value.") if predictions.shape[1] != len(proba): raise ValueError("mismatch in shape of proba and predictions.") if predictions.shape[1] != len(opt_class): raise ValueError("mismatch in shape of opt_class and predictions.") for m in range(n_class): if (np.any(np.logical_or(scores[:,m] < 0, scores[:,m] > 1)) and proba[m]): warnings.warn("scores fall outside the [0,1] interval for " + "classifier {}. Setting proba[m]=False.".format(m)) proba[m] = False return proba, opt_class
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_call'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '6', 'type': 'block', 'children': ['7', '13', '28', '34', '45', '54']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '13', 'type': 'if_statement', 'children': ['14', '21']},{'id': '14', 'type': 'not_operator', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'has_key'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'string', 'children': [], 'value': '"method"'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'raise_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'RpcException'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'ERR_INVALID_REQ'},{'id': '27', 'type': 'string', 'children': [], 'value': '"Invalid Request. No \'method\'."'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '31', 'type': 'subscript', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '33', 'type': 'string', 'children': [], 'value': '"method"'},{'id': '34', 'type': 'if_statement', 'children': ['35', '38']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': '=='},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '37', 'type': 'string', 'children': [], 'value': '"barrister-idl"'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'return_statement', 'children': ['40']},{'id': '40', 'type': 'attribute', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'contract'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'idl_parsed'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '50']},{'id': '47', 'type': 'pattern_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'iface_name'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'func_name'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'unpack_method'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '54', 'type': 'if_statement', 'children': ['55', '63', '192']},{'id': '55', 'type': 'call', 'children': ['56', '61']},{'id': '56', 'type': 'attribute', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'handlers'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'has_key'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'iface_name'},{'id': '63', 'type': 'block', 'children': ['64', '72', '80']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'iface_impl'},{'id': '67', 'type': 'subscript', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'handlers'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'iface_name'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '77', 'type': 'argument_list', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'iface_impl'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'func_name'},{'id': '80', 'type': 'if_statement', 'children': ['81', '82', '177']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '82', 'type': 'block', 'children': ['83', '103', '119', '140', '159', '175']},{'id': '83', 'type': 'if_statement', 'children': ['84', '90', '97']},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'has_key'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'string', 'children': [], 'value': '"params"'},{'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': 'params'},{'id': '94', 'type': 'subscript', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '96', 'type': 'string', 'children': [], 'value': '"params"'},{'id': '97', 'type': 'else_clause', 'children': ['98']},{'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': 'params'},{'id': '102', 'type': 'list', 'children': [], 'value': '[ ]'},{'id': '103', 'type': 'if_statement', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'validate_req'},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '115']},{'id': '110', 'type': 'attribute', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'contract'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'validate_request'},{'id': '115', 'type': 'argument_list', 'children': ['116', '117', '118']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'iface_name'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'func_name'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '119', 'type': 'if_statement', 'children': ['120', '125']},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '122', 'type': 'argument_list', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'iface_impl'},{'id': '124', 'type': 'string', 'children': [], 'value': '"barrister_pre"'},{'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': 'pre_hook'},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '131', 'type': 'argument_list', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'iface_impl'},{'id': '133', 'type': 'string', 'children': [], 'value': '"barrister_pre"'},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'pre_hook'},{'id': '137', 'type': 'argument_list', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '140', 'type': 'if_statement', 'children': ['141', '142', '151']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '142', 'type': 'block', 'children': ['143']},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'list_splat', 'children': ['150']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '151', 'type': 'else_clause', 'children': ['152']},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '158', 'type': 'argument_list', 'children': []},{'id': '159', 'type': 'if_statement', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'validate_resp'},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '171']},{'id': '166', 'type': 'attribute', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'contract'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'validate_response'},{'id': '171', 'type': 'argument_list', 'children': ['172', '173', '174']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'iface_name'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'func_name'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '175', 'type': 'return_statement', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '177', 'type': 'else_clause', 'children': ['178']},{'id': '178', 'type': 'block', 'children': ['179', '186']},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '182', 'type': 'binary_operator', 'children': ['183', '184'], 'value': '%'},{'id': '183', 'type': 'string', 'children': [], 'value': '"Method \'%s\' not found"'},{'id': '184', 'type': '()', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '186', 'type': 'raise_statement', 'children': ['187']},{'id': '187', 'type': 'call', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'RpcException'},{'id': '189', 'type': 'argument_list', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'ERR_METHOD_NOT_FOUND'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '192', 'type': 'else_clause', 'children': ['193']},{'id': '193', 'type': 'block', 'children': ['194', '201']},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '197', 'type': 'binary_operator', 'children': ['198', '199'], 'value': '%'},{'id': '198', 'type': 'string', 'children': [], 'value': '"No implementation of \'%s\' found"'},{'id': '199', 'type': '()', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'iface_name'},{'id': '201', 'type': 'raise_statement', 'children': ['202']},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'RpcException'},{'id': '204', 'type': 'argument_list', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'ERR_METHOD_NOT_FOUND'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'msg'}
def _call(self, context): req = context.request if not req.has_key("method"): raise RpcException(ERR_INVALID_REQ, "Invalid Request. No 'method'.") method = req["method"] if method == "barrister-idl": return self.contract.idl_parsed iface_name, func_name = unpack_method(method) if self.handlers.has_key(iface_name): iface_impl = self.handlers[iface_name] func = getattr(iface_impl, func_name) if func: if req.has_key("params"): params = req["params"] else: params = [ ] if self.validate_req: self.contract.validate_request(iface_name, func_name, params) if hasattr(iface_impl, "barrister_pre"): pre_hook = getattr(iface_impl, "barrister_pre") pre_hook(context, params) if params: result = func(*params) else: result = func() if self.validate_resp: self.contract.validate_response(iface_name, func_name, result) return result else: msg = "Method '%s' not found" % (method) raise RpcException(ERR_METHOD_NOT_FOUND, msg) else: msg = "No implementation of '%s' found" % (iface_name) raise RpcException(ERR_METHOD_NOT_FOUND, msg)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'validate'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'expected_type'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'is_array'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '8', 'type': 'block', 'children': ['9', '190']},{'id': '9', 'type': 'if_statement', 'children': ['10', '13', '29', '75', '100', '126', '149', '174']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': '=='},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'if_statement', 'children': ['15', '18', '23']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'expected_type'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'optional'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'return_statement', 'children': ['20']},{'id': '20', 'type': 'expression_list', 'children': ['21', '22']},{'id': '21', 'type': 'True', 'children': []},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'else_clause', 'children': ['24']},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'return_statement', 'children': ['26']},{'id': '26', 'type': 'expression_list', 'children': ['27', '28']},{'id': '27', 'type': 'False', 'children': []},{'id': '28', 'type': 'string', 'children': [], 'value': '"Value cannot be null"'},{'id': '29', 'type': 'elif_clause', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'is_array'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'if_statement', 'children': ['33', '39', '48']},{'id': '33', 'type': 'not_operator', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'return_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '44', 'type': 'identifier', 'children': [], 'value': '_type_err'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '47', 'type': 'string', 'children': [], 'value': '"list"'},{'id': '48', 'type': 'else_clause', 'children': ['49']},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'for_statement', 'children': ['51', '52', '53']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '53', 'type': 'block', 'children': ['54', '67']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '59']},{'id': '56', 'type': 'pattern_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'validate'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65', '66']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'expected_type'},{'id': '65', 'type': 'False', 'children': []},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '67', 'type': 'if_statement', 'children': ['68', '70']},{'id': '68', 'type': 'not_operator', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'return_statement', 'children': ['72']},{'id': '72', 'type': 'expression_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '75', 'type': 'elif_clause', 'children': ['76', '81']},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '80'], 'value': '=='},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'expected_type'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '80', 'type': 'string', 'children': [], 'value': '"int"'},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'if_statement', 'children': ['83', '91']},{'id': '83', 'type': 'not_operator', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '88', 'type': 'tuple', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'long'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'return_statement', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '96', 'type': 'identifier', 'children': [], 'value': '_type_err'},{'id': '97', 'type': 'argument_list', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '99', 'type': 'string', 'children': [], 'value': '"int"'},{'id': '100', 'type': 'elif_clause', 'children': ['101', '106']},{'id': '101', 'type': 'comparison_operator', 'children': ['102', '105'], 'value': '=='},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'expected_type'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '105', 'type': 'string', 'children': [], 'value': '"float"'},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'if_statement', 'children': ['108', '117']},{'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': 'val'},{'id': '113', 'type': 'tuple', 'children': ['114', '115', '116']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'long'},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'return_statement', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '122', 'type': 'identifier', 'children': [], 'value': '_type_err'},{'id': '123', 'type': 'argument_list', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '125', 'type': 'string', 'children': [], 'value': '"float"'},{'id': '126', 'type': 'elif_clause', 'children': ['127', '132']},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '131'], 'value': '=='},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'expected_type'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '131', 'type': 'string', 'children': [], 'value': '"bool"'},{'id': '132', 'type': 'block', 'children': ['133']},{'id': '133', 'type': 'if_statement', 'children': ['134', '140']},{'id': '134', 'type': 'not_operator', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '137', 'type': 'argument_list', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'return_statement', 'children': ['142']},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '145', 'type': 'identifier', 'children': [], 'value': '_type_err'},{'id': '146', 'type': 'argument_list', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '148', 'type': 'string', 'children': [], 'value': '"bool"'},{'id': '149', 'type': 'elif_clause', 'children': ['150', '155']},{'id': '150', 'type': 'comparison_operator', 'children': ['151', '154'], 'value': '=='},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'expected_type'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '154', 'type': 'string', 'children': [], 'value': '"string"'},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'if_statement', 'children': ['157', '165']},{'id': '157', 'type': 'not_operator', 'children': ['158']},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '160', 'type': 'argument_list', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '162', 'type': 'tuple', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'unicode'},{'id': '165', 'type': 'block', 'children': ['166']},{'id': '166', 'type': 'return_statement', 'children': ['167']},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '170', 'type': 'identifier', 'children': [], 'value': '_type_err'},{'id': '171', 'type': 'argument_list', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '173', 'type': 'string', 'children': [], 'value': '"string"'},{'id': '174', 'type': 'else_clause', 'children': ['175']},{'id': '175', 'type': 'block', 'children': ['176']},{'id': '176', 'type': 'return_statement', 'children': ['177']},{'id': '177', 'type': 'call', 'children': ['178', '188']},{'id': '178', 'type': 'attribute', 'children': ['179', '187']},{'id': '179', 'type': 'call', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'expected_type'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'validate'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '190', 'type': 'return_statement', 'children': ['191']},{'id': '191', 'type': 'expression_list', 'children': ['192', '193']},{'id': '192', 'type': 'True', 'children': []},{'id': '193', 'type': 'None', 'children': []}
def validate(self, expected_type, is_array, val): if val == None: if expected_type.optional: return True, None else: return False, "Value cannot be null" elif is_array: if not isinstance(val, list): return self._type_err(val, "list") else: for v in val: ok, msg = self.validate(expected_type, False, v) if not ok: return ok, msg elif expected_type.type == "int": if not isinstance(val, (long, int)): return self._type_err(val, "int") elif expected_type.type == "float": if not isinstance(val, (float, int, long)): return self._type_err(val, "float") elif expected_type.type == "bool": if not isinstance(val, bool): return self._type_err(val, "bool") elif expected_type.type == "string": if not isinstance(val, (str, unicode)): return self._type_err(val, "string") else: return self.get(expected_type.type).validate(val) return True, None
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'validate'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '6', 'type': 'block', 'children': ['7', '25', '90', '99', '132']},{'id': '7', 'type': 'if_statement', 'children': ['8', '14']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '13'], 'value': 'is'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'return_statement', 'children': ['16']},{'id': '16', 'type': 'expression_list', 'children': ['17', '18']},{'id': '17', 'type': 'False', 'children': []},{'id': '18', 'type': 'binary_operator', 'children': ['19', '20'], 'value': '%'},{'id': '19', 'type': 'string', 'children': [], 'value': '"%s is not a dict"'},{'id': '20', 'type': '()', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '25', 'type': 'for_statement', 'children': ['26', '29', '34']},{'id': '26', 'type': 'pattern_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'block', 'children': ['35', '44']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'field'},{'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': 'field'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '44', 'type': 'if_statement', 'children': ['45', '46', '78']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '46', 'type': 'block', 'children': ['47', '64']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '52']},{'id': '49', 'type': 'pattern_list', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'msg'},{'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': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'contract'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'validate'},{'id': '58', 'type': 'argument_list', 'children': ['59', '60', '63']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'is_array'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '64', 'type': 'if_statement', 'children': ['65', '67']},{'id': '65', 'type': 'not_operator', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'return_statement', 'children': ['69']},{'id': '69', 'type': 'expression_list', 'children': ['70', '71']},{'id': '70', 'type': 'False', 'children': []},{'id': '71', 'type': 'binary_operator', 'children': ['72', '73'], 'value': '%'},{'id': '72', 'type': 'string', 'children': [], 'value': '"field \'%s\': %s"'},{'id': '73', 'type': 'tuple', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '78', 'type': 'else_clause', 'children': ['79']},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'return_statement', 'children': ['81']},{'id': '81', 'type': 'expression_list', 'children': ['82', '83']},{'id': '82', 'type': 'False', 'children': []},{'id': '83', 'type': 'binary_operator', 'children': ['84', '85'], 'value': '%'},{'id': '84', 'type': 'string', 'children': [], 'value': '"field \'%s\' not found in struct %s"'},{'id': '85', 'type': 'tuple', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'all_fields'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'get_all_fields'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'list', 'children': [], 'value': '[]'},{'id': '99', 'type': 'for_statement', 'children': ['100', '101', '102']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'all_fields'},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'if_statement', 'children': ['104', '118']},{'id': '104', 'type': 'boolean_operator', 'children': ['105', '114'], 'value': 'and'},{'id': '105', 'type': 'not_operator', 'children': ['106']},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'has_key'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '114', 'type': 'not_operator', 'children': ['115']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'optional'},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'return_statement', 'children': ['120']},{'id': '120', 'type': 'expression_list', 'children': ['121', '122']},{'id': '121', 'type': 'False', 'children': []},{'id': '122', 'type': 'binary_operator', 'children': ['123', '124'], 'value': '%'},{'id': '123', 'type': 'string', 'children': [], 'value': '"field \'%s\' missing from: %s"'},{'id': '124', 'type': 'tuple', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '128', 'type': 'call', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '132', 'type': 'return_statement', 'children': ['133']},{'id': '133', 'type': 'expression_list', 'children': ['134', '135']},{'id': '134', 'type': 'True', 'children': []},{'id': '135', 'type': 'None', 'children': []}
def validate(self, val): if type(val) is not dict: return False, "%s is not a dict" % (str(val)) for k, v in val.items(): field = self.field(k) if field: ok, msg = self.contract.validate(field, field.is_array, v) if not ok: return False, "field '%s': %s" % (field.name, msg) else: return False, "field '%s' not found in struct %s" % (k, self.name) all_fields = self.get_all_fields([]) for field in all_fields: if not val.has_key(field.name) and not field.optional: return False, "field '%s' missing from: %s" % (field.name, str(val)) return True, None
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_struct'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '5', 'type': 'block', 'children': ['6', '12', '20', '33', '37', '41', '45', '92', '96', '100', '104', '108', '207', '211']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'docs'},{'id': '9', 'type': 'subscript', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '11', 'type': 'string', 'children': [], 'value': "'comment'"},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '15', 'type': 'binary_operator', 'children': ['16', '17'], 'value': '%'},{'id': '16', 'type': 'string', 'children': [], 'value': '\'<span class="k">struct</span> <span class="gs">%s</span>\''},{'id': '17', 'type': 'subscript', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '19', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '20', 'type': 'if_statement', 'children': ['21', '24']},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '23', 'type': 'string', 'children': [], 'value': "'extends'"},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'augmented_assignment', 'children': ['27', '28'], 'value': '+='},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '28', 'type': 'binary_operator', 'children': ['29', '30'], 'value': '%'},{'id': '29', 'type': 'string', 'children': [], 'value': '\' extends <span class="gs">%s</span>\''},{'id': '30', 'type': 'subscript', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '32', 'type': 'string', 'children': [], 'value': "'extends'"},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'augmented_assignment', 'children': ['35', '36'], 'value': '+='},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '36', 'type': 'string', 'children': [], 'value': "' {\\n'"},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'namelen'},{'id': '40', 'type': 'integer', 'children': [], 'value': '0'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'typelen'},{'id': '44', 'type': 'integer', 'children': [], 'value': '0'},{'id': '45', 'type': 'for_statement', 'children': ['46', '47', '50']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '49', 'type': 'string', 'children': [], 'value': '"fields"'},{'id': '50', 'type': 'block', 'children': ['51', '64', '83']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'tlen'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'format_type'},{'id': '59', 'type': 'argument_list', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'includeOptional'},{'id': '63', 'type': 'False', 'children': []},{'id': '64', 'type': 'if_statement', 'children': ['65', '73']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '72'], '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': 'subscript', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '71', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'namelen'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'namelen'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '82', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '83', 'type': 'if_statement', 'children': ['84', '87']},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': '>'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'tlen'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'typelen'},{'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': 'typelen'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'tlen'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'augmented_assignment', 'children': ['94', '95'], 'value': '+='},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'namelen'},{'id': '95', 'type': 'integer', 'children': [], 'value': '1'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'augmented_assignment', 'children': ['98', '99'], 'value': '+='},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'typelen'},{'id': '99', 'type': 'integer', 'children': [], 'value': '1'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'formatstr'},{'id': '103', 'type': 'string', 'children': [], 'value': '\' <span class="nv">%s</span><span class="kt">%s %s</span>\\n\''},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '107', 'type': 'integer', 'children': [], 'value': '0'},{'id': '108', 'type': 'for_statement', 'children': ['109', '110', '113']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '112', 'type': 'string', 'children': [], 'value': '"fields"'},{'id': '113', 'type': 'block', 'children': ['114', '152', '156', '174', '203']},{'id': '114', 'type': 'if_statement', 'children': ['115', '125']},{'id': '115', 'type': 'boolean_operator', 'children': ['116', '122'], 'value': 'and'},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'has_key'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'string', 'children': [], 'value': "'comment'"},{'id': '122', 'type': 'subscript', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '124', 'type': 'string', 'children': [], 'value': "'comment'"},{'id': '125', 'type': 'block', 'children': ['126', '135']},{'id': '126', 'type': 'if_statement', 'children': ['127', '130']},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': '>'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '129', 'type': 'integer', 'children': [], 'value': '0'},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'augmented_assignment', 'children': ['133', '134'], 'value': '+='},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '134', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '135', 'type': 'for_statement', 'children': ['136', '137', '145']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '137', 'type': 'call', 'children': ['138', '143']},{'id': '138', 'type': 'attribute', 'children': ['139', '142']},{'id': '139', 'type': 'subscript', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '141', 'type': 'string', 'children': [], 'value': "'comment'"},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '145', 'type': 'block', 'children': ['146']},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'augmented_assignment', 'children': ['148', '149'], 'value': '+='},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '149', 'type': 'binary_operator', 'children': ['150', '151'], 'value': '%'},{'id': '150', 'type': 'string', 'children': [], 'value': '\' <span class="c1">// %s</span>\\n\''},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '155', 'type': 'string', 'children': [], 'value': '""'},{'id': '156', 'type': 'if_statement', 'children': ['157', '169']},{'id': '157', 'type': 'boolean_operator', 'children': ['158', '164'], 'value': 'and'},{'id': '158', 'type': 'call', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'has_key'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'string', 'children': [], 'value': "'optional'"},{'id': '164', 'type': 'comparison_operator', 'children': ['165', '168'], 'value': '=='},{'id': '165', 'type': 'subscript', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '167', 'type': 'string', 'children': [], 'value': "'optional'"},{'id': '168', 'type': 'True', 'children': []},{'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': 'opt'},{'id': '173', 'type': 'string', 'children': [], 'value': '" [optional]"'},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'augmented_assignment', 'children': ['176', '177'], 'value': '+='},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '177', 'type': 'binary_operator', 'children': ['178', '179'], 'value': '%'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'formatstr'},{'id': '179', 'type': 'tuple', 'children': ['180', '189', '202']},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'string'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'ljust'},{'id': '184', 'type': 'argument_list', 'children': ['185', '188']},{'id': '185', 'type': 'subscript', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '187', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'namelen'},{'id': '189', 'type': 'call', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'string'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'ljust'},{'id': '193', 'type': 'argument_list', 'children': ['194', '201']},{'id': '194', 'type': 'call', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'format_type'},{'id': '196', 'type': 'argument_list', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '198', 'type': 'keyword_argument', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'includeOptional'},{'id': '200', 'type': 'False', 'children': []},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'typelen'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'augmented_assignment', 'children': ['205', '206'], 'value': '+='},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '206', 'type': 'integer', 'children': [], 'value': '1'},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'augmented_assignment', 'children': ['209', '210'], 'value': '+='},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '210', 'type': 'string', 'children': [], 'value': '"}"'},{'id': '211', 'type': 'return_statement', 'children': ['212']},{'id': '212', 'type': 'call', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'to_section'},{'id': '214', 'type': 'argument_list', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'docs'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'code'}
def parse_struct(s): docs = s['comment'] code = '<span class="k">struct</span> <span class="gs">%s</span>' % s['name'] if s['extends']: code += ' extends <span class="gs">%s</span>' % s['extends'] code += ' {\n' namelen = 0 typelen = 0 for v in s["fields"]: tlen = len(format_type(v, includeOptional=False)) if len(v['name']) > namelen: namelen = len(v['name']) if tlen > typelen: typelen = tlen namelen += 1 typelen += 1 formatstr = ' <span class="nv">%s</span><span class="kt">%s %s</span>\n' i = 0 for v in s["fields"]: if v.has_key('comment') and v['comment']: if i > 0: code += "\n" for line in v['comment'].split("\n"): code += ' <span class="c1">// %s</span>\n' % line opt = "" if v.has_key('optional') and v['optional'] == True: opt = " [optional]" code += formatstr % (string.ljust(v['name'], namelen), string.ljust(format_type(v, includeOptional=False), typelen), opt) i += 1 code += "}" return to_section(docs, code)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_interface'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'iface'},{'id': '5', 'type': 'block', 'children': ['6', '10', '16', '24', '129', '133', '144']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sections'},{'id': '9', 'type': 'list', 'children': [], 'value': '[ ]'},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'docs'},{'id': '13', 'type': 'subscript', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'iface'},{'id': '15', 'type': 'string', 'children': [], 'value': "'comment'"},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '19', 'type': 'binary_operator', 'children': ['20', '21'], 'value': '%'},{'id': '20', 'type': 'string', 'children': [], 'value': '\'<span class="k">interface</span> <span class="gs">%s</span> {\\n\''},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'iface'},{'id': '23', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '24', 'type': 'for_statement', 'children': ['25', '26', '29']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '26', 'type': 'subscript', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'iface'},{'id': '28', 'type': 'string', 'children': [], 'value': '"functions"'},{'id': '29', 'type': 'block', 'children': ['30', '38', '42', '76', '87']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'func_code'},{'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '%'},{'id': '34', 'type': 'string', 'children': [], 'value': '\' <span class="nf">%s</span>(\''},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '37', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '41', 'type': 'integer', 'children': [], 'value': '0'},{'id': '42', 'type': 'for_statement', 'children': ['43', '44', '47']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '46', 'type': 'string', 'children': [], 'value': '"params"'},{'id': '47', 'type': 'block', 'children': ['48', '63']},{'id': '48', 'type': 'if_statement', 'children': ['49', '52', '57']},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': '=='},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '51', 'type': 'integer', 'children': [], 'value': '0'},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '56', 'type': 'integer', 'children': [], 'value': '1'},{'id': '57', 'type': 'else_clause', 'children': ['58']},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'augmented_assignment', 'children': ['61', '62'], 'value': '+='},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'func_code'},{'id': '62', 'type': 'string', 'children': [], 'value': '", "'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'augmented_assignment', 'children': ['65', '66'], 'value': '+='},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'func_code'},{'id': '66', 'type': 'binary_operator', 'children': ['67', '68'], 'value': '%'},{'id': '67', 'type': 'string', 'children': [], 'value': '\'<span class="na">%s</span> <span class="kt">%s</span>\''},{'id': '68', 'type': 'tuple', 'children': ['69', '72']},{'id': '69', 'type': 'subscript', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '71', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'format_type'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'augmented_assignment', 'children': ['78', '79'], 'value': '+='},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'func_code'},{'id': '79', 'type': 'binary_operator', 'children': ['80', '81'], 'value': '%'},{'id': '80', 'type': 'string', 'children': [], 'value': '\') <span class="kt">%s</span>\\n\''},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'format_type'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '86', 'type': 'string', 'children': [], 'value': "'returns'"},{'id': '87', 'type': 'if_statement', 'children': ['88', '98', '123']},{'id': '88', 'type': 'boolean_operator', 'children': ['89', '95'], 'value': 'and'},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'has_key'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'string', 'children': [], 'value': "'comment'"},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '97', 'type': 'string', 'children': [], 'value': "'comment'"},{'id': '98', 'type': 'block', 'children': ['99', '113', '119']},{'id': '99', 'type': 'if_statement', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'code'},{'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': 'sections'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'to_section'},{'id': '110', 'type': 'argument_list', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'docs'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'docs'},{'id': '116', 'type': 'subscript', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '118', 'type': 'string', 'children': [], 'value': "'comment'"},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'func_code'},{'id': '123', 'type': 'else_clause', 'children': ['124']},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'augmented_assignment', 'children': ['127', '128'], 'value': '+='},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'func_code'},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'augmented_assignment', 'children': ['131', '132'], 'value': '+='},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '132', 'type': 'string', 'children': [], 'value': '"}"'},{'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': 'sections'},{'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': 'to_section'},{'id': '141', 'type': 'argument_list', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'docs'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '144', 'type': 'return_statement', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'sections'}
def parse_interface(iface): sections = [ ] docs = iface['comment'] code = '<span class="k">interface</span> <span class="gs">%s</span> {\n' % iface['name'] for v in iface["functions"]: func_code = ' <span class="nf">%s</span>(' % v['name'] i = 0 for p in v["params"]: if i == 0: i = 1 else: func_code += ", " func_code += '<span class="na">%s</span> <span class="kt">%s</span>' % (p['name'], format_type(p)) func_code += ') <span class="kt">%s</span>\n' % format_type(v['returns']) if v.has_key('comment') and v['comment']: if code: sections.append(to_section(docs, code)) docs = v['comment'] code = func_code else: code += func_code code += "}" sections.append(to_section(docs, code)) return sections
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'run'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '12', '18', '24', '30', '37', '60', '80', '86', '94', '101', '211', '218']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'configfile'},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'configfile'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sockets'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'sockets'},{'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': 'model'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'initialize'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'configfile'},{'id': '37', 'type': 'if_statement', 'children': ['38', '43', '51']},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '42'], 'value': '=='},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '42', 'type': 'string', 'children': [], 'value': "'pause'"},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'string', 'children': [], 'value': '"model initialized and started in pause mode, waiting for requests"'},{'id': '51', 'type': 'else_clause', 'children': ['52']},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'string', 'children': [], 'value': '"model started and initialized, running"'},{'id': '60', 'type': 'if_statement', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'tracker'},{'id': '64', 'type': 'block', 'children': ['65', '71']},{'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': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'register'},{'id': '70', 'type': 'argument_list', 'children': []},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'atexit'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'register'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'unregister'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'process_incoming'},{'id': '85', 'type': 'argument_list', 'children': []},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'counter'},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '93', 'type': 'argument_list', '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': 'logger'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'string', 'children': [], 'value': '"Entering timeloop..."'},{'id': '101', 'type': 'for_statement', 'children': ['102', '103', '104']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'counter'},{'id': '104', 'type': 'block', 'children': ['105', '126', '134', '145', '152', '158']},{'id': '105', 'type': 'while_statement', 'children': ['106', '111', '118']},{'id': '106', 'type': 'comparison_operator', 'children': ['107', '110'], 'value': '=='},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '110', 'type': 'string', 'children': [], 'value': '"pause"'},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'process_incoming'},{'id': '117', 'type': 'argument_list', 'children': []},{'id': '118', 'type': 'else_clause', 'children': ['119']},{'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': 'self'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'process_incoming'},{'id': '125', 'type': 'argument_list', 'children': []},{'id': '126', 'type': 'if_statement', 'children': ['127', '132']},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '131'], 'value': '=='},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '131', 'type': 'string', 'children': [], 'value': '"quit"'},{'id': '132', 'type': 'block', 'children': ['133']},{'id': '133', 'type': 'break_statement', 'children': []},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '137', 'type': 'boolean_operator', 'children': ['138', '143'], 'value': 'or'},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'get_time_step'},{'id': '142', 'type': 'argument_list', 'children': []},{'id': '143', 'type': 'unary_operator', 'children': ['144'], 'value': '-'},{'id': '144', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'model'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '152', 'type': 'if_statement', 'children': ['153', '156']},{'id': '153', 'type': 'binary_operator', 'children': ['154', '155'], 'value': '%'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '156', 'type': 'block', 'children': ['157']},{'id': '157', 'type': 'continue_statement', 'children': []},{'id': '158', 'type': 'for_statement', 'children': ['159', '160', '163']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'output_vars'},{'id': '163', 'type': 'block', 'children': ['164', '173', '183', '195']},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'get_var'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '176', 'type': 'dictionary', 'children': ['177', '180']},{'id': '177', 'type': 'pair', 'children': ['178', '179']},{'id': '178', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '180', 'type': 'pair', 'children': ['181', '182']},{'id': '181', 'type': 'string', 'children': [], 'value': "'iteration'"},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'call', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'string', 'children': [], 'value': '"sending {}"'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '195', 'type': 'if_statement', 'children': ['196', '199']},{'id': '196', 'type': 'comparison_operator', 'children': ['197', '198'], 'value': 'in'},{'id': '197', 'type': 'string', 'children': [], 'value': "'pub'"},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'sockets'},{'id': '199', 'type': 'block', 'children': ['200']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'send_array'},{'id': '203', 'type': 'argument_list', 'children': ['204', '207', '208']},{'id': '204', 'type': 'subscript', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'sockets'},{'id': '206', 'type': 'string', 'children': [], 'value': "'pub'"},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '208', 'type': 'keyword_argument', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'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': 'logger'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'string', 'children': [], 'value': '"Finalizing..."'},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'finalize'},{'id': '223', 'type': 'argument_list', 'children': []}
def run(self): model = self.model configfile = self.configfile interval = self.interval sockets = self.sockets model.initialize(configfile) if model.state == 'pause': logger.info( "model initialized and started in pause mode, waiting for requests" ) else: logger.info("model started and initialized, running") if self.tracker: self.register() atexit.register(self.unregister) self.process_incoming() counter = itertools.count() logger.info("Entering timeloop...") for i in counter: while model.state == "pause": self.process_incoming() else: self.process_incoming() if model.state == "quit": break dt = model.get_time_step() or -1 model.update(dt) if i % interval: continue for key in self.output_vars: value = model.get_var(key) metadata = {'name': key, 'iteration': i} logger.debug("sending {}".format(metadata)) if 'pub' in sockets: send_array(sockets['pub'], value, metadata=metadata) logger.info("Finalizing...") model.finalize()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'save'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '9', 'type': 'block', 'children': ['10', '185']},{'id': '10', 'type': 'if_statement', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'publication'},{'id': '14', 'type': 'block', 'children': ['15', '21', '35', '86', '100']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'publication'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'publication'},{'id': '21', 'type': 'if_statement', 'children': ['22', '26']},{'id': '22', 'type': 'not_operator', 'children': ['23']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'publication'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '35', 'type': 'if_statement', 'children': ['36', '40']},{'id': '36', 'type': 'not_operator', 'children': ['37']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'subtitle'},{'id': '40', 'type': 'block', 'children': ['41', '47', '69']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'first_author'},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'publication'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'first_author'},{'id': '47', 'type': 'if_statement', 'children': ['48', '53', '58']},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': '=='},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'first_author'},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'publication'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'last_author'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'authors'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'first_author'},{'id': '58', 'type': 'else_clause', 'children': ['59']},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'authors'},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'string', 'children': [], 'value': "'{} et al.'"},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'first_author'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'subtitle'},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'string', 'children': [], 'value': "'{}, {} ({})'"},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80', '83']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'authors'},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'publication'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'journal'},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'publication'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '86', 'type': 'if_statement', 'children': ['87', '91']},{'id': '87', 'type': 'not_operator', 'children': ['88']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'publication'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'abstract'},{'id': '100', 'type': 'if_statement', 'children': ['101', '111']},{'id': '101', 'type': 'boolean_operator', 'children': ['102', '107'], 'value': 'and'},{'id': '102', 'type': 'attribute', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'publication'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '107', 'type': 'not_operator', 'children': ['108']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '111', 'type': 'block', 'children': ['112', '124']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '115', 'type': 'binary_operator', 'children': ['116', '121'], 'value': '-'},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'timezone'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '120', 'type': 'argument_list', 'children': []},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'publish_datetime'},{'id': '124', 'type': 'if_statement', 'children': ['125', '140']},{'id': '125', 'type': 'boolean_operator', 'children': ['126', '135'], 'value': 'and'},{'id': '126', 'type': 'comparison_operator', 'children': ['127', '130'], 'value': '<='},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'publish_datetime'},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'timezone'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '134', 'type': 'argument_list', 'children': []},{'id': '135', 'type': 'comparison_operator', 'children': ['136', '139'], 'value': '=='},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'days'},{'id': '139', 'type': 'integer', 'children': [], 'value': '0'},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'publish_datetime'},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '150', 'type': 'argument_list', 'children': ['151', '161', '173']},{'id': '151', 'type': 'keyword_argument', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'attribute', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'publication'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '161', 'type': 'keyword_argument', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'month'},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'boolean_operator', 'children': ['167', '172'], 'value': 'or'},{'id': '167', 'type': 'attribute', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'publication'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'month'},{'id': '172', 'type': 'integer', 'children': [], 'value': '1'},{'id': '173', 'type': 'keyword_argument', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'boolean_operator', 'children': ['179', '184'], 'value': 'or'},{'id': '179', 'type': 'attribute', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'publication'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '184', 'type': 'integer', 'children': [], 'value': '1'},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'call', 'children': ['187', '192']},{'id': '187', 'type': 'attribute', 'children': ['188', '191']},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '190', 'type': 'argument_list', 'children': []},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'save'},{'id': '192', 'type': 'argument_list', 'children': ['193', '195']},{'id': '193', 'type': 'list_splat', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '195', 'type': 'dictionary_splat', 'children': ['196']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'kwargs'}
def save(self, *args, **kwargs): if self.publication: publication = self.publication if not self.title: self.title = publication.title if not self.subtitle: first_author = publication.first_author if first_author == publication.last_author: authors = first_author else: authors = '{} et al.'.format(first_author) self.subtitle = '{}, {} ({})'.format(authors, publication.journal, publication.year) if not self.description: self.description = publication.abstract if self.publication.year and not self.pk: delta = timezone.now() - self.publish_datetime if self.publish_datetime <= timezone.now() and delta.days == 0: self.publish_datetime = datetime.datetime( year=int(self.publication.year), month=int(self.publication.month or 1), day=int(self.publication.day or 1), ) super().save(*args, **kwargs)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'cmd'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '7', 'type': 'block', 'children': ['8', '20', '26']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'implements'},{'id': '11', 'type': 'list', 'children': ['12', '13', '14', '15', '16', '17', '18', '19'], 'value': "['the golden gate bridge', 'a large trout', 'a clue-by-four', 'a fresh haddock', 'moon', 'an Itanium', 'fwilson', 'a wombat']"},{'id': '12', 'type': 'string', 'children': [], 'value': "'the golden gate bridge'"},{'id': '13', 'type': 'string', 'children': [], 'value': "'a large trout'"},{'id': '14', 'type': 'string', 'children': [], 'value': "'a clue-by-four'"},{'id': '15', 'type': 'string', 'children': [], 'value': "'a fresh haddock'"},{'id': '16', 'type': 'string', 'children': [], 'value': "'moon'"},{'id': '17', 'type': 'string', 'children': [], 'value': "'an Itanium'"},{'id': '18', 'type': 'string', 'children': [], 'value': "'fwilson'"},{'id': '19', 'type': 'string', 'children': [], 'value': "'a wombat'"},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'methods'},{'id': '23', 'type': 'list', 'children': ['24', '25'], 'value': "['around a bit', 'upside the head']"},{'id': '24', 'type': 'string', 'children': [], 'value': "'around a bit'"},{'id': '25', 'type': 'string', 'children': [], 'value': "'upside the head'"},{'id': '26', 'type': 'if_statement', 'children': ['27', '29', '99']},{'id': '27', 'type': 'not_operator', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '29', 'type': 'block', 'children': ['30', '49', '75', '79']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '33', 'type': 'conditional_expression', 'children': ['34', '37', '42'], 'value': 'if'},{'id': '34', 'type': 'subscript', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '36', 'type': 'string', 'children': [], 'value': "'target'"},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '41'], 'value': '!='},{'id': '38', 'type': 'subscript', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '40', 'type': 'string', 'children': [], 'value': "'target'"},{'id': '41', 'type': 'string', 'children': [], 'value': "'private'"},{'id': '42', 'type': 'subscript', 'children': ['43', '48']},{'id': '43', 'type': 'subscript', 'children': ['44', '47']},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '46', 'type': 'string', 'children': [], 'value': "'config'"},{'id': '47', 'type': 'string', 'children': [], 'value': "'core'"},{'id': '48', 'type': 'string', 'children': [], 'value': "'channel'"},{'id': '49', 'type': 'with_statement', 'children': ['50', '57']},{'id': '50', 'type': 'with_clause', 'children': ['51']},{'id': '51', 'type': 'with_item', 'children': ['52']},{'id': '52', 'type': 'attribute', 'children': ['53', '56']},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '55', 'type': 'string', 'children': [], 'value': "'handler'"},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'data_lock'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '74']},{'id': '65', 'type': 'attribute', 'children': ['66', '73']},{'id': '66', 'type': 'subscript', 'children': ['67', '72']},{'id': '67', 'type': 'attribute', 'children': ['68', '71']},{'id': '68', 'type': 'subscript', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '70', 'type': 'string', 'children': [], 'value': "'handler'"},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'channels'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '74', 'type': 'argument_list', 'children': []},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'slap'},{'id': '78', 'type': 'string', 'children': [], 'value': "'slaps %s %s with %s'"},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '82', 'type': 'argument_list', 'children': ['83', '98']},{'id': '83', 'type': 'binary_operator', 'children': ['84', '85'], 'value': '%'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'slap'},{'id': '85', 'type': 'tuple', 'children': ['86', '90', '94']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'choice'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'choice'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'methods'},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'choice'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'implements'},{'id': '98', 'type': 'string', 'children': [], 'value': "'action'"},{'id': '99', 'type': 'else_clause', 'children': ['100']},{'id': '100', 'type': 'block', 'children': ['101', '105', '112', '116', '124', '130', '134', '138', '286', '297', '321']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'reason'},{'id': '104', 'type': 'string', 'children': [], 'value': "''"},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'choice'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'methods'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'implement'},{'id': '115', 'type': 'string', 'children': [], 'value': "''"},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '123', 'type': 'argument_list', 'children': []},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'slapee'},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '129', 'type': 'integer', 'children': [], 'value': '0'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '133', 'type': 'integer', 'children': [], 'value': '1'},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '137', 'type': 'False', 'children': []},{'id': '138', 'type': 'while_statement', 'children': ['139', '145']},{'id': '139', 'type': 'comparison_operator', 'children': ['140', '141'], 'value': '<'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '145', 'type': 'block', 'children': ['146', '282']},{'id': '146', 'type': 'if_statement', 'children': ['147', '152', '208', '270']},{'id': '147', 'type': 'comparison_operator', 'children': ['148', '151'], 'value': '=='},{'id': '148', 'type': 'subscript', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '151', 'type': 'string', 'children': [], 'value': "'for'"},{'id': '152', 'type': 'block', 'children': ['153', '157', '166', '170', '200']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '156', 'type': 'True', 'children': []},{'id': '157', 'type': 'if_statement', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'reason'},{'id': '159', 'type': 'block', 'children': ['160', '165']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'string', 'children': [], 'value': '"Invalid Syntax: You can only have one for clause!"'},{'id': '165', 'type': 'return_statement', 'children': []},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'augmented_assignment', 'children': ['168', '169'], 'value': '+='},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '169', 'type': 'integer', 'children': [], 'value': '1'},{'id': '170', 'type': 'while_statement', 'children': ['171', '177']},{'id': '171', 'type': 'comparison_operator', 'children': ['172', '173'], 'value': '<'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '177', 'type': 'block', 'children': ['178', '186', '190', '196']},{'id': '178', 'type': 'if_statement', 'children': ['179', '184']},{'id': '179', 'type': 'comparison_operator', 'children': ['180', '183'], 'value': '=='},{'id': '180', 'type': 'subscript', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '183', 'type': 'string', 'children': [], 'value': "'with'"},{'id': '184', 'type': 'block', 'children': ['185']},{'id': '185', 'type': 'break_statement', 'children': []},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'augmented_assignment', 'children': ['188', '189'], 'value': '+='},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'reason'},{'id': '189', 'type': 'string', 'children': [], 'value': '" "'},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'augmented_assignment', 'children': ['192', '193'], 'value': '+='},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'reason'},{'id': '193', 'type': 'subscript', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'augmented_assignment', 'children': ['198', '199'], 'value': '+='},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '199', 'type': 'integer', 'children': [], 'value': '1'},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'reason'},{'id': '203', 'type': 'call', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'reason'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '207', 'type': 'argument_list', 'children': []},{'id': '208', 'type': 'elif_clause', 'children': ['209', '214']},{'id': '209', 'type': 'comparison_operator', 'children': ['210', '213'], 'value': '=='},{'id': '210', 'type': 'subscript', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '213', 'type': 'string', 'children': [], 'value': "'with'"},{'id': '214', 'type': 'block', 'children': ['215', '219', '228', '232', '262']},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '218', 'type': 'True', 'children': []},{'id': '219', 'type': 'if_statement', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'implement'},{'id': '221', 'type': 'block', 'children': ['222', '227']},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'string', 'children': [], 'value': '"Invalid Synatx: You can only have one with clause!"'},{'id': '227', 'type': 'return_statement', 'children': []},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'augmented_assignment', 'children': ['230', '231'], 'value': '+='},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '231', 'type': 'integer', 'children': [], 'value': '1'},{'id': '232', 'type': 'while_statement', 'children': ['233', '239']},{'id': '233', 'type': 'comparison_operator', 'children': ['234', '235'], 'value': '<'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '235', 'type': 'call', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '237', 'type': 'argument_list', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '239', 'type': 'block', 'children': ['240', '248', '254', '258']},{'id': '240', 'type': 'if_statement', 'children': ['241', '246']},{'id': '241', 'type': 'comparison_operator', 'children': ['242', '245'], 'value': '=='},{'id': '242', 'type': 'subscript', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '245', 'type': 'string', 'children': [], 'value': "'for'"},{'id': '246', 'type': 'block', 'children': ['247']},{'id': '247', 'type': 'break_statement', 'children': []},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'augmented_assignment', 'children': ['250', '251'], 'value': '+='},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'implement'},{'id': '251', 'type': 'subscript', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'augmented_assignment', 'children': ['256', '257'], 'value': '+='},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'implement'},{'id': '257', 'type': 'string', 'children': [], 'value': "' '"},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'augmented_assignment', 'children': ['260', '261'], 'value': '+='},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '261', 'type': 'integer', 'children': [], 'value': '1'},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'assignment', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'implement'},{'id': '265', 'type': 'call', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'implement'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '269', 'type': 'argument_list', 'children': []},{'id': '270', 'type': 'elif_clause', 'children': ['271', '273']},{'id': '271', 'type': 'not_operator', 'children': ['272']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '273', 'type': 'block', 'children': ['274']},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'augmented_assignment', 'children': ['276', '277'], 'value': '+='},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'slapee'},{'id': '277', 'type': 'binary_operator', 'children': ['278', '279'], 'value': '+'},{'id': '278', 'type': 'string', 'children': [], 'value': "' '"},{'id': '279', 'type': 'subscript', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'augmented_assignment', 'children': ['284', '285'], 'value': '+='},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '285', 'type': 'integer', 'children': [], 'value': '1'},{'id': '286', 'type': 'if_statement', 'children': ['287', '289']},{'id': '287', 'type': 'not_operator', 'children': ['288']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'implement'},{'id': '289', 'type': 'block', 'children': ['290']},{'id': '290', 'type': 'expression_statement', 'children': ['291']},{'id': '291', 'type': 'assignment', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'implement'},{'id': '293', 'type': 'call', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'choice'},{'id': '295', 'type': 'argument_list', 'children': ['296']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'implements'},{'id': '297', 'type': 'if_statement', 'children': ['298', '299', '310']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'reason'},{'id': '299', 'type': 'block', 'children': ['300']},{'id': '300', 'type': 'expression_statement', 'children': ['301']},{'id': '301', 'type': 'assignment', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'slap'},{'id': '303', 'type': 'binary_operator', 'children': ['304', '305'], 'value': '%'},{'id': '304', 'type': 'string', 'children': [], 'value': "'slaps %s %s with %s for %s'"},{'id': '305', 'type': 'tuple', 'children': ['306', '307', '308', '309']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'slapee'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'implement'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'reason'},{'id': '310', 'type': 'else_clause', 'children': ['311']},{'id': '311', 'type': 'block', 'children': ['312']},{'id': '312', 'type': 'expression_statement', 'children': ['313']},{'id': '313', 'type': 'assignment', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'slap'},{'id': '315', 'type': 'binary_operator', 'children': ['316', '317'], 'value': '%'},{'id': '316', 'type': 'string', 'children': [], 'value': "'slaps %s %s with %s'"},{'id': '317', 'type': 'tuple', 'children': ['318', '319', '320']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'slapee'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'implement'},{'id': '321', 'type': 'expression_statement', 'children': ['322']},{'id': '322', 'type': 'call', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '324', 'type': 'argument_list', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'slap'},{'id': '326', 'type': 'string', 'children': [], 'value': "'action'"}
def cmd(send, msg, args): implements = ['the golden gate bridge', 'a large trout', 'a clue-by-four', 'a fresh haddock', 'moon', 'an Itanium', 'fwilson', 'a wombat'] methods = ['around a bit', 'upside the head'] if not msg: channel = args['target'] if args['target'] != 'private' else args['config']['core']['channel'] with args['handler'].data_lock: users = list(args['handler'].channels[channel].users()) slap = 'slaps %s %s with %s' send(slap % (choice(users), choice(methods), choice(implements)), 'action') else: reason = '' method = choice(methods) implement = '' msg = msg.split() slapee = msg[0] i = 1 args = False while i < len(msg): if msg[i] == 'for': args = True if reason: send("Invalid Syntax: You can only have one for clause!") return i += 1 while i < len(msg): if msg[i] == 'with': break reason += " " reason += msg[i] i += 1 reason = reason.strip() elif msg[i] == 'with': args = True if implement: send("Invalid Synatx: You can only have one with clause!") return i += 1 while i < len(msg): if msg[i] == 'for': break implement += msg[i] implement += ' ' i += 1 implement = implement.strip() elif not args: slapee += ' ' + msg[i] i += 1 if not implement: implement = choice(implements) if reason: slap = 'slaps %s %s with %s for %s' % (slapee, method, implement, reason) else: slap = 'slaps %s %s with %s' % (slapee, method, implement) send(slap, 'action')
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'cmd'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '7', 'type': 'block', 'children': ['8', '18', '24', '53', '79', '96', '113', '119', '125', '144', '155']},{'id': '8', 'type': 'if_statement', 'children': ['9', '11']},{'id': '9', 'type': 'not_operator', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '11', 'type': 'block', 'children': ['12', '17']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'string', 'children': [], 'value': '"Invalid Syntax."'},{'id': '17', 'type': 'return_statement', 'children': []},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'char'},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '23', 'type': 'integer', 'children': [], 'value': '0'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '27', 'type': 'list_comprehension', 'children': ['28', '35']},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34']},{'id': '33', 'type': 'string', 'children': [], 'value': "r'\\/'"},{'id': '34', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '35', 'type': 'for_in_clause', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '41', 'type': 'argument_list', 'children': ['42', '45', '50']},{'id': '42', 'type': 'binary_operator', 'children': ['43', '44'], 'value': '%'},{'id': '43', 'type': 'string', 'children': [], 'value': "r'(?<!\\\\)\\%s'"},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'char'},{'id': '45', 'type': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '47', 'type': 'slice', 'children': ['48', '49']},{'id': '48', 'type': 'integer', 'children': [], 'value': '1'},{'id': '49', 'type': 'colon', 'children': []},{'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'maxsplit'},{'id': '52', 'type': 'integer', 'children': [], 'value': '2'},{'id': '53', 'type': 'if_statement', 'children': ['54', '71']},{'id': '54', 'type': 'boolean_operator', 'children': ['55', '61'], 'value': 'and'},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '60'], 'value': '=='},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '60', 'type': 'integer', 'children': [], 'value': '2'},{'id': '61', 'type': 'call', 'children': ['62', '69']},{'id': '62', 'type': 'attribute', 'children': ['63', '68']},{'id': '63', 'type': 'subscript', 'children': ['64', '67']},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '66', 'type': 'string', 'children': [], 'value': "'config'"},{'id': '67', 'type': 'string', 'children': [], 'value': "'feature'"},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'getboolean'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'string', 'children': [], 'value': "'lazyregex'"},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'string', 'children': [], 'value': "''"},{'id': '79', 'type': 'if_statement', 'children': ['80', '89']},{'id': '80', 'type': 'boolean_operator', 'children': ['81', '83'], 'value': 'or'},{'id': '81', 'type': 'not_operator', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '88'], 'value': '<'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '88', 'type': 'integer', 'children': [], 'value': '3'},{'id': '89', 'type': 'block', 'children': ['90', '95']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'string', 'children': [], 'value': '"Invalid Syntax."'},{'id': '95', 'type': 'return_statement', 'children': []},{'id': '96', 'type': 'if_statement', 'children': ['97', '102']},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '101'], 'value': '=='},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '100', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '101', 'type': 'string', 'children': [], 'value': "'privmsg'"},{'id': '102', 'type': 'block', 'children': ['103', '112']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'binary_operator', 'children': ['108', '109'], 'value': '%'},{'id': '108', 'type': 'string', 'children': [], 'value': '"Don\'t worry, %s is not a grammar Nazi."'},{'id': '109', 'type': 'subscript', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '111', 'type': 'string', 'children': [], 'value': "'botnick'"},{'id': '112', 'type': 'return_statement', 'children': []},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'string'},{'id': '116', 'type': 'subscript', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '118', 'type': 'integer', 'children': [], 'value': '0'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'replacement'},{'id': '122', 'type': 'subscript', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '124', 'type': 'integer', 'children': [], 'value': '1'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'modifiers'},{'id': '128', 'type': 'call', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'get_modifiers'},{'id': '130', 'type': 'argument_list', 'children': ['131', '134', '137']},{'id': '131', 'type': 'subscript', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '133', 'type': 'integer', 'children': [], 'value': '2'},{'id': '134', 'type': 'subscript', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '136', 'type': 'string', 'children': [], 'value': "'nick'"},{'id': '137', 'type': 'subscript', 'children': ['138', '143']},{'id': '138', 'type': 'subscript', 'children': ['139', '142']},{'id': '139', 'type': 'subscript', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '141', 'type': 'string', 'children': [], 'value': "'config'"},{'id': '142', 'type': 'string', 'children': [], 'value': "'core'"},{'id': '143', 'type': 'string', 'children': [], 'value': "'nickregex'"},{'id': '144', 'type': 'if_statement', 'children': ['145', '148']},{'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': 'is'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'modifiers'},{'id': '147', 'type': 'None', 'children': []},{'id': '148', 'type': 'block', 'children': ['149', '154']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'string', 'children': [], 'value': '"Invalid modifiers."'},{'id': '154', 'type': 'return_statement', 'children': []},{'id': '155', 'type': 'try_statement', 'children': ['156', '264']},{'id': '156', 'type': 'block', 'children': ['157', '179', '194', '202', '221', '249']},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'regex'},{'id': '160', 'type': 'conditional_expression', 'children': ['161', '170', '173'], 'value': 'if'},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'compile'},{'id': '165', 'type': 'argument_list', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'string'},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'IGNORECASE'},{'id': '170', 'type': 'subscript', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'modifiers'},{'id': '172', 'type': 'string', 'children': [], 'value': "'ignorecase'"},{'id': '173', 'type': 'call', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'compile'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'string'},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'get_log'},{'id': '184', 'type': 'argument_list', 'children': ['185', '188', '191']},{'id': '185', 'type': 'subscript', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '187', 'type': 'string', 'children': [], 'value': "'db'"},{'id': '188', 'type': 'subscript', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '190', 'type': 'string', 'children': [], 'value': "'target'"},{'id': '191', 'type': 'subscript', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'modifiers'},{'id': '193', 'type': 'string', 'children': [], 'value': "'nick'"},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'workers'},{'id': '197', 'type': 'attribute', 'children': ['198', '201']},{'id': '198', 'type': 'subscript', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '200', 'type': 'string', 'children': [], 'value': "'handler'"},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'workers'},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '205', 'type': 'call', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'workers'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'run_pool'},{'id': '209', 'type': 'argument_list', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'do_replace'},{'id': '211', 'type': 'list', 'children': ['212', '213', '218', '219', '220'], 'value': "[log, args['config']['core'], char, regex, replacement]"},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '213', 'type': 'subscript', 'children': ['214', '217']},{'id': '214', 'type': 'subscript', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '216', 'type': 'string', 'children': [], 'value': "'config'"},{'id': '217', 'type': 'string', 'children': [], 'value': "'core'"},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'char'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'regex'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'replacement'},{'id': '221', 'type': 'try_statement', 'children': ['222', '232']},{'id': '222', 'type': 'block', 'children': ['223']},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'assignment', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '226', 'type': 'call', 'children': ['227', '230']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '230', 'type': 'argument_list', 'children': ['231']},{'id': '231', 'type': 'integer', 'children': [], 'value': '5'},{'id': '232', 'type': 'except_clause', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'multiprocessing'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'TimeoutError'},{'id': '236', 'type': 'block', 'children': ['237', '243', '248']},{'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': 'workers'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'restart_pool'},{'id': '242', 'type': 'argument_list', 'children': []},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'call', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'string', 'children': [], 'value': '"Sed regex timed out."'},{'id': '248', 'type': 'return_statement', 'children': []},{'id': '249', 'type': 'if_statement', 'children': ['250', '251', '257']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '251', 'type': 'block', 'children': ['252']},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'call', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '257', 'type': 'else_clause', 'children': ['258']},{'id': '258', 'type': 'block', 'children': ['259']},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'call', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '262', 'type': 'argument_list', 'children': ['263']},{'id': '263', 'type': 'string', 'children': [], 'value': '"No match found."'},{'id': '264', 'type': 'except_clause', 'children': ['265', '271']},{'id': '265', 'type': 'as_pattern', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'sre_constants'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '269', 'type': 'as_pattern_target', 'children': ['270']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '271', 'type': 'block', 'children': ['272']},{'id': '272', 'type': 'raise_statement', 'children': ['273']},{'id': '273', 'type': 'call', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'CommandFailedException'},{'id': '275', 'type': 'argument_list', 'children': ['276']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'ex'}
def cmd(send, msg, args): if not msg: send("Invalid Syntax.") return char = msg[0] msg = [x.replace(r'\/', '/') for x in re.split(r'(?<!\\)\%s' % char, msg[1:], maxsplit=2)] if len(msg) == 2 and args['config']['feature'].getboolean('lazyregex'): msg.append('') if not msg or len(msg) < 3: send("Invalid Syntax.") return if args['type'] == 'privmsg': send("Don't worry, %s is not a grammar Nazi." % args['botnick']) return string = msg[0] replacement = msg[1] modifiers = get_modifiers(msg[2], args['nick'], args['config']['core']['nickregex']) if modifiers is None: send("Invalid modifiers.") return try: regex = re.compile(string, re.IGNORECASE) if modifiers['ignorecase'] else re.compile(string) log = get_log(args['db'], args['target'], modifiers['nick']) workers = args['handler'].workers result = workers.run_pool(do_replace, [log, args['config']['core'], char, regex, replacement]) try: msg = result.get(5) except multiprocessing.TimeoutError: workers.restart_pool() send("Sed regex timed out.") return if msg: send(msg) else: send("No match found.") except sre_constants.error as ex: raise CommandFailedException(ex)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_add_single_session_to_to_ordered_dict'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'dataset_index'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'recommended_only'},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'for_statement', 'children': ['10', '13', '19']},{'id': '10', 'type': 'pattern_list', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'model_index'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '19', 'type': 'block', 'children': ['20', '24', '76', '85', '96']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'show_null'},{'id': '23', 'type': 'False', 'children': []},{'id': '24', 'type': 'if_statement', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'recommended_only'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'if_statement', 'children': ['28', '31', '62']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'recommendation_enabled'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'if_statement', 'children': ['33', '38', '51', '59']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '37'], 'value': 'is'},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'recommended_model'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'if_statement', 'children': ['40', '43', '48']},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': '=='},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'model_index'},{'id': '42', 'type': 'integer', 'children': [], 'value': '0'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'show_null'},{'id': '47', 'type': 'True', 'children': []},{'id': '48', 'type': 'else_clause', 'children': ['49']},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'continue_statement', 'children': []},{'id': '51', 'type': 'elif_clause', 'children': ['52', '57']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '56'], 'value': '=='},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'recommended_model'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'pass_statement', 'children': []},{'id': '59', 'type': 'else_clause', 'children': ['60']},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'continue_statement', 'children': []},{'id': '62', 'type': 'else_clause', 'children': ['63']},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'if_statement', 'children': ['65', '68', '73']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': '=='},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'model_index'},{'id': '67', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'show_null'},{'id': '72', 'type': 'True', 'children': []},{'id': '73', 'type': 'else_clause', 'children': ['74']},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'continue_statement', 'children': []},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '83']},{'id': '78', 'type': 'attribute', 'children': ['79', '82']},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '81', 'type': 'string', 'children': [], 'value': '"dataset_index"'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'dataset_index'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'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': 'd'},{'id': '90', 'type': 'string', 'children': [], 'value': '"doses_dropped"'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'doses_dropped'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '100', 'type': 'identifier', 'children': [], 'value': '_to_df'},{'id': '101', 'type': 'argument_list', 'children': ['102', '103', '104']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'model_index'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'show_null'}
def _add_single_session_to_to_ordered_dict(self, d, dataset_index, recommended_only): for model_index, model in enumerate(self.models): show_null = False if recommended_only: if self.recommendation_enabled: if self.recommended_model is None: if model_index == 0: show_null = True else: continue elif self.recommended_model == model: pass else: continue else: if model_index == 0: show_null = True else: continue d["dataset_index"].append(dataset_index) d["doses_dropped"].append(self.doses_dropped) model._to_df(d, model_index, show_null)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_group_models'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '12', '99', '127', '146']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'od'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '11', 'type': 'argument_list', 'children': []},{'id': '12', 'type': 'for_statement', 'children': ['13', '16', '22']},{'id': '13', 'type': 'pattern_list', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '22', 'type': 'block', 'children': ['23', '32']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30', '31']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '30', 'type': 'string', 'children': [], 'value': '"output"'},{'id': '31', 'type': 'dictionary', 'children': []},{'id': '32', 'type': 'if_statement', 'children': ['33', '52', '90']},{'id': '33', 'type': 'boolean_operator', 'children': ['34', '47'], 'value': 'and'},{'id': '34', 'type': 'boolean_operator', 'children': ['35', '41'], 'value': 'and'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'string', 'children': [], 'value': '"AIC"'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'string', 'children': [], 'value': '"BMD"'},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '51'], 'value': '>'},{'id': '48', 'type': 'subscript', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '50', 'type': 'string', 'children': [], 'value': '"BMD"'},{'id': '51', 'type': 'integer', 'children': [], 'value': '0'},{'id': '52', 'type': 'block', 'children': ['53', '67']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'string', 'children': [], 'value': '"{}-{}"'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '60', 'type': 'argument_list', 'children': ['61', '64']},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '63', 'type': 'string', 'children': [], 'value': '"AIC"'},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '66', 'type': 'string', 'children': [], 'value': '"BMD"'},{'id': '67', 'type': 'if_statement', 'children': ['68', '71', '81']},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'in'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'od'},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '79']},{'id': '74', 'type': 'attribute', 'children': ['75', '78']},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'od'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '81', 'type': 'else_clause', 'children': ['82']},{'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': 'od'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '88', 'type': 'list', 'children': ['89'], 'value': '[model]'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'model'},{'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', '97']},{'id': '94', 'type': 'subscript', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'od'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '97', 'type': 'list', 'children': ['98'], 'value': '[model]'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '99', 'type': 'function_definition', 'children': ['100', '101', '103']},{'id': '100', 'type': 'function_name', 'children': [], 'value': '_get_num_params'},{'id': '101', 'type': 'parameters', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '103', 'type': 'block', 'children': ['104']},{'id': '104', 'type': 'return_statement', 'children': ['105']},{'id': '105', 'type': '()', 'children': ['106']},{'id': '106', 'type': 'conditional_expression', 'children': ['107', '115', '126'], 'value': 'if'},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'subscript', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '114', 'type': 'string', 'children': [], 'value': '"parameters"'},{'id': '115', 'type': 'boolean_operator', 'children': ['116', '121'], 'value': 'and'},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '118', 'type': 'argument_list', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '120', 'type': 'string', 'children': [], 'value': '"output"'},{'id': '121', 'type': 'comparison_operator', 'children': ['122', '123'], 'value': 'in'},{'id': '122', 'type': 'string', 'children': [], 'value': '"parameters"'},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '126', 'type': 'integer', 'children': [], 'value': '0'},{'id': '127', 'type': 'for_statement', 'children': ['128', '131', '136']},{'id': '128', 'type': 'pattern_list', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '130', 'type': 'identifier', 'children': [], 'value': '_models'},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'od'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '135', 'type': 'argument_list', 'children': []},{'id': '136', 'type': 'block', 'children': ['137']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': '_models'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'keyword_argument', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '145', 'type': 'identifier', 'children': [], 'value': '_get_num_params'},{'id': '146', 'type': 'return_statement', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'od'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '154', 'type': 'argument_list', 'children': []}
def _group_models(self): od = OrderedDict() for i, model in enumerate(self.models): output = getattr(model, "output", {}) if output.get("AIC") and output.get("BMD") and output["BMD"] > 0: key = "{}-{}".format(output["AIC"], output["BMD"]) if key in od: od[key].append(model) else: od[key] = [model] else: od[i] = [model] def _get_num_params(model): return ( len(model.output["parameters"]) if hasattr(model, "output") and "parameters" in model.output else 0 ) for key, _models in od.items(): _models.sort(key=_get_num_params) return list(od.values())
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'random_stats'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'all_stats'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'race'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'ch_class'},{'id': '8', 'type': 'block', 'children': ['9', '13', '17', '38', '42', '135']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '12', 'type': 'list', 'children': [], 'value': '[]'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '16', 'type': 'dictionary', 'children': []},{'id': '17', 'type': 'for_statement', 'children': ['18', '19', '20']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'all_stats'},{'id': '20', 'type': 'block', 'children': ['21', '30']},{'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': 'stats'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'subscript', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '29', 'type': 'string', 'children': [], 'value': "'stat'"},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '37']},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '34', 'type': 'subscript', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '36', 'type': 'string', 'children': [], 'value': "'stat'"},{'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': 'cur_stat'},{'id': '41', 'type': 'integer', 'children': [], 'value': '0'},{'id': '42', 'type': 'for_statement', 'children': ['43', '44', '45']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '45', 'type': 'block', 'children': ['46', '75', '104', '129']},{'id': '46', 'type': 'for_statement', 'children': ['47', '50', '58']},{'id': '47', 'type': 'pattern_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'ndx'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'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': 'classes'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'dat'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'if_statement', 'children': ['60', '65']},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '64'], 'value': '=='},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '63', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'ch_class'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'cur_stat'},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'subscript', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '75', 'type': 'for_statement', 'children': ['76', '79', '87']},{'id': '76', 'type': 'pattern_list', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'ndx'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'attribute', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'races'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'dat'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'if_statement', 'children': ['89', '94']},{'id': '89', 'type': 'comparison_operator', 'children': ['90', '93'], 'value': '=='},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '92', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'race'},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'augmented_assignment', 'children': ['97', '98'], 'value': '+='},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'cur_stat'},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '104', 'type': 'if_statement', 'children': ['105', '108', '113']},{'id': '105', 'type': 'comparison_operator', 'children': ['106', '107'], 'value': '<'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'cur_stat'},{'id': '107', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'cur_stat'},{'id': '112', 'type': 'integer', 'children': [], 'value': '1'},{'id': '113', 'type': 'elif_clause', 'children': ['114', '117']},{'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': '>'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'cur_stat'},{'id': '116', 'type': 'integer', 'children': [], 'value': '10'},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'if_statement', 'children': ['119', '124']},{'id': '119', 'type': 'comparison_operator', 'children': ['120', '121'], 'value': 'not'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '121', 'type': 'tuple', 'children': ['122', '123']},{'id': '122', 'type': 'string', 'children': [], 'value': "'Health'"},{'id': '123', 'type': 'string', 'children': [], 'value': "'max_health'"},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'cur_stat'},{'id': '128', 'type': 'integer', 'children': [], 'value': '10'},{'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': 'res'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'cur_stat'},{'id': '135', 'type': 'return_statement', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'res'}
def random_stats(self, all_stats, race, ch_class): stats = [] res = {} for s in all_stats: stats.append(s['stat']) res[s['stat']] = 0 cur_stat = 0 for stat in stats: for ndx, i in enumerate(self.classes.dat): if i['name'] == ch_class: cur_stat = int(i[stat]) for ndx, i in enumerate(self.races.dat): if i['name'] == race: cur_stat += int(i[stat]) if cur_stat < 1: cur_stat = 1 elif cur_stat > 10: if stat not in ('Health', 'max_health'): cur_stat = 10 res[stat] = cur_stat return res
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'palette'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'fg'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'bg'},{'id': '7', 'type': 'unary_operator', 'children': ['8'], 'value': '-'},{'id': '8', 'type': 'integer', 'children': [], 'value': '1'},{'id': '9', 'type': 'block', 'children': ['10', '24', '38', '52', '76', '94', '134', '174', '187']},{'id': '10', 'type': 'if_statement', 'children': ['11', '17']},{'id': '11', 'type': 'not_operator', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '14', 'type': 'argument_list', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'palette'},{'id': '16', 'type': 'string', 'children': [], 'value': '"counter"'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'palette'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'counter'},{'id': '23', 'type': 'integer', 'children': [], 'value': '1'},{'id': '24', 'type': 'if_statement', 'children': ['25', '31']},{'id': '25', 'type': 'not_operator', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'palette'},{'id': '30', 'type': 'string', 'children': [], 'value': '"selections"'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'palette'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'selections'},{'id': '37', 'type': 'dictionary', 'children': []},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'selection'},{'id': '41', 'type': 'binary_operator', 'children': ['42', '43'], 'value': '%'},{'id': '42', 'type': 'string', 'children': [], 'value': '"%s%s"'},{'id': '43', 'type': 'tuple', 'children': ['44', '48']},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'fg'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'bg'},{'id': '52', 'type': 'if_statement', 'children': ['53', '59']},{'id': '53', 'type': 'not_operator', 'children': ['54']},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'in'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'selection'},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'palette'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'selections'},{'id': '59', 'type': 'block', 'children': ['60', '70']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '67']},{'id': '62', 'type': 'subscript', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'palette'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'selections'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'selection'},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'palette'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'counter'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'augmented_assignment', 'children': ['72', '75'], 'value': '+='},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'palette'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'counter'},{'id': '75', 'type': 'integer', 'children': [], 'value': '1'},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'colors'},{'id': '79', 'type': 'list_comprehension', 'children': ['80', '81', '87']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '81', 'type': 'for_in_clause', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'dir'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': '_curses'},{'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': 'c'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'string', 'children': [], 'value': "'COLOR'"},{'id': '94', 'type': 'if_statement', 'children': ['95', '100']},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '97', 'type': 'argument_list', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'fg'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'if_statement', 'children': ['102', '112', '118']},{'id': '102', 'type': 'not_operator', 'children': ['103']},{'id': '103', 'type': 'comparison_operator', 'children': ['104', '111'], 'value': 'in'},{'id': '104', 'type': 'binary_operator', 'children': ['105', '106'], 'value': '+'},{'id': '105', 'type': 'string', 'children': [], 'value': '"COLOR_"'},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'fg'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '110', 'type': 'argument_list', 'children': []},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'colors'},{'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': 'fg'},{'id': '116', 'type': 'unary_operator', 'children': ['117'], 'value': '-'},{'id': '117', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'fg'},{'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': '_curses'},{'id': '127', 'type': 'binary_operator', 'children': ['128', '129'], 'value': '+'},{'id': '128', 'type': 'string', 'children': [], 'value': '"COLOR_"'},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'fg'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '133', 'type': 'argument_list', 'children': []},{'id': '134', 'type': 'if_statement', 'children': ['135', '140']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '137', 'type': 'argument_list', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'bg'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'if_statement', 'children': ['142', '152', '158']},{'id': '142', 'type': 'not_operator', 'children': ['143']},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '151'], 'value': 'in'},{'id': '144', 'type': 'binary_operator', 'children': ['145', '146'], 'value': '+'},{'id': '145', 'type': 'string', 'children': [], 'value': '"COLOR_"'},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'bg'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '150', 'type': 'argument_list', 'children': []},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'colors'},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'bg'},{'id': '156', 'type': 'unary_operator', 'children': ['157'], 'value': '-'},{'id': '157', 'type': 'integer', 'children': [], 'value': '1'},{'id': '158', 'type': 'else_clause', 'children': ['159']},{'id': '159', 'type': 'block', 'children': ['160']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'bg'},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '165', 'type': 'argument_list', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': '_curses'},{'id': '167', 'type': 'binary_operator', 'children': ['168', '169'], 'value': '+'},{'id': '168', 'type': 'string', 'children': [], 'value': '"COLOR_"'},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'bg'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '173', 'type': 'argument_list', 'children': []},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': '_curses'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'init_pair'},{'id': '179', 'type': 'argument_list', 'children': ['180', '185', '186']},{'id': '180', 'type': 'subscript', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'palette'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'selections'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'selection'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'fg'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'bg'},{'id': '187', 'type': 'return_statement', 'children': ['188']},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': '_curses'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'color_pair'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'subscript', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'palette'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'selections'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'selection'}
def palette(fg, bg=-1): if not hasattr(palette, "counter"): palette.counter = 1 if not hasattr(palette, "selections"): palette.selections = {} selection = "%s%s" % (str(fg), str(bg)) if not selection in palette.selections: palette.selections[selection] = palette.counter palette.counter += 1 colors = [c for c in dir(_curses) if c.startswith('COLOR')] if isinstance(fg, str): if not "COLOR_"+fg.upper() in colors: fg = -1 else: fg = getattr(_curses, "COLOR_"+fg.upper()) if isinstance(bg, str): if not "COLOR_"+bg.upper() in colors: bg = -1 else: bg = getattr(_curses, "COLOR_"+bg.upper()) _curses.init_pair(palette.selections[selection], fg, bg) return _curses.color_pair(palette.selections[selection])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'coordinate'},{'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': 'panes'},{'id': '7', 'type': 'list', 'children': [], 'value': '[]'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '10', 'type': 'integer', 'children': [], 'value': '0'},{'id': '11', 'type': 'block', 'children': ['12', '16']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '15', 'type': 'integer', 'children': [], 'value': '0'},{'id': '16', 'type': 'for_statement', 'children': ['17', '20', '26']},{'id': '17', 'type': 'pattern_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'panes'},{'id': '26', 'type': 'block', 'children': ['27', '31', '213']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '30', 'type': 'integer', 'children': [], 'value': '0'},{'id': '31', 'type': 'if_statement', 'children': ['32', '37', '133']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '37', 'type': 'block', 'children': ['38', '42', '121']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'current_height'},{'id': '41', 'type': 'integer', 'children': [], 'value': '0'},{'id': '42', 'type': 'for_statement', 'children': ['43', '46', '50']},{'id': '43', 'type': 'pattern_list', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'pane'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '50', 'type': 'block', 'children': ['51', '57', '63', '69', '81', '109', '117']},{'id': '51', 'type': 'if_statement', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'pane'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'hidden'},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'continue_statement', 'children': []},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'current_width'},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'pane'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'current_height'},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'pane'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '72', 'type': 'tuple', 'children': ['73', '76']},{'id': '73', 'type': 'tuple', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '76', 'type': 'tuple', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '78', 'type': 'binary_operator', 'children': ['79', '80'], 'value': '+'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'current_width'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '84', 'type': 'tuple', 'children': ['85', '96']},{'id': '85', 'type': 'tuple', 'children': ['86', '95']},{'id': '86', 'type': 'binary_operator', 'children': ['87', '88'], 'value': '+'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '88', 'type': '()', 'children': ['89']},{'id': '89', 'type': 'conditional_expression', 'children': ['90', '91', '94'], 'value': 'if'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'current_height'},{'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': '>'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'current_height'},{'id': '93', 'type': 'integer', 'children': [], 'value': '1'},{'id': '94', 'type': 'integer', 'children': [], 'value': '0'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '96', 'type': 'tuple', 'children': ['97', '106']},{'id': '97', 'type': 'binary_operator', 'children': ['98', '99'], 'value': '+'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '99', 'type': '()', 'children': ['100']},{'id': '100', 'type': 'conditional_expression', 'children': ['101', '102', '105'], 'value': 'if'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'current_height'},{'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': '>'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'current_height'},{'id': '104', 'type': 'integer', 'children': [], 'value': '1'},{'id': '105', 'type': 'integer', 'children': [], 'value': '0'},{'id': '106', 'type': 'binary_operator', 'children': ['107', '108'], 'value': '+'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'current_width'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'pane'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'coords'},{'id': '114', 'type': 'list', 'children': ['115', '116'], 'value': '[upper, lower]'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'augmented_assignment', 'children': ['119', '120'], 'value': '+='},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'current_width'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'augmented_assignment', 'children': ['123', '124'], 'value': '+='},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '124', 'type': '()', 'children': ['125']},{'id': '125', 'type': 'conditional_expression', 'children': ['126', '129', '132'], 'value': 'if'},{'id': '126', 'type': 'binary_operator', 'children': ['127', '128'], 'value': '+'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'current_height'},{'id': '128', 'type': 'integer', 'children': [], 'value': '1'},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': '>'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'current_height'},{'id': '131', 'type': 'integer', 'children': [], 'value': '1'},{'id': '132', 'type': 'integer', 'children': [], 'value': '1'},{'id': '133', 'type': 'else_clause', 'children': ['134']},{'id': '134', 'type': 'block', 'children': ['135', '141', '147', '153', '165', '193', '201']},{'id': '135', 'type': 'if_statement', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'hidden'},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'continue_statement', 'children': []},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'current_width'},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'current_height'},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '156', 'type': 'tuple', 'children': ['157', '160']},{'id': '157', 'type': 'tuple', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '160', 'type': 'tuple', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '162', 'type': 'binary_operator', 'children': ['163', '164'], 'value': '+'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'current_width'},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '168', 'type': 'tuple', 'children': ['169', '180']},{'id': '169', 'type': 'tuple', 'children': ['170', '179']},{'id': '170', 'type': 'binary_operator', 'children': ['171', '172'], 'value': '+'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '172', 'type': '()', 'children': ['173']},{'id': '173', 'type': 'conditional_expression', 'children': ['174', '175', '178'], 'value': 'if'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'current_height'},{'id': '175', 'type': 'comparison_operator', 'children': ['176', '177'], 'value': '>'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'current_height'},{'id': '177', 'type': 'integer', 'children': [], 'value': '1'},{'id': '178', 'type': 'integer', 'children': [], 'value': '0'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '180', 'type': 'tuple', 'children': ['181', '190']},{'id': '181', 'type': 'binary_operator', 'children': ['182', '183'], 'value': '+'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '183', 'type': '()', 'children': ['184']},{'id': '184', 'type': 'conditional_expression', 'children': ['185', '186', '189'], 'value': 'if'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'current_height'},{'id': '186', 'type': 'comparison_operator', 'children': ['187', '188'], 'value': '>'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'current_height'},{'id': '188', 'type': 'integer', 'children': [], 'value': '1'},{'id': '189', 'type': 'integer', 'children': [], 'value': '0'},{'id': '190', 'type': 'binary_operator', 'children': ['191', '192'], 'value': '+'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'current_width'},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'coords'},{'id': '198', 'type': 'list', 'children': ['199', '200'], 'value': '[upper, lower]'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'augmented_assignment', 'children': ['203', '204'], 'value': '+='},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '204', 'type': '()', 'children': ['205']},{'id': '205', 'type': 'conditional_expression', 'children': ['206', '209', '212'], 'value': 'if'},{'id': '206', 'type': 'binary_operator', 'children': ['207', '208'], 'value': '+'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'current_height'},{'id': '208', 'type': 'integer', 'children': [], 'value': '1'},{'id': '209', 'type': 'comparison_operator', 'children': ['210', '211'], 'value': '>'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'current_height'},{'id': '211', 'type': 'integer', 'children': [], 'value': '1'},{'id': '212', 'type': 'integer', 'children': [], 'value': '1'},{'id': '213', 'type': 'if_statement', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '217', 'type': 'block', 'children': ['218', '233', '259']},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'assignment', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'coordinates'},{'id': '221', 'type': 'binary_operator', 'children': ['222', '223'], 'value': '+'},{'id': '222', 'type': 'string', 'children': [], 'value': '"Coordinates: "'},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'list_comprehension', 'children': ['227', '230']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'coords'},{'id': '230', 'type': 'for_in_clause', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '233', 'type': 'if_statement', 'children': ['234', '242']},{'id': '234', 'type': 'comparison_operator', 'children': ['235', '239'], 'value': '>'},{'id': '235', 'type': 'call', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '237', 'type': 'argument_list', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'coordinates'},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '242', 'type': 'block', 'children': ['243', '255']},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'assignment', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'coordinates'},{'id': '246', 'type': 'subscript', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'coordinates'},{'id': '248', 'type': 'slice', 'children': ['249', '250']},{'id': '249', 'type': 'colon', 'children': []},{'id': '250', 'type': 'binary_operator', 'children': ['251', '254'], 'value': '-'},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '254', 'type': 'integer', 'children': [], 'value': '3'},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'augmented_assignment', 'children': ['257', '258'], 'value': '+='},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'coordinates'},{'id': '258', 'type': 'string', 'children': [], 'value': "'...'"},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'call', 'children': ['261', '264']},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'addstr'},{'id': '264', 'type': 'argument_list', 'children': ['265', '270', '271']},{'id': '265', 'type': 'binary_operator', 'children': ['266', '269'], 'value': '-'},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '269', 'type': 'integer', 'children': [], 'value': '3'},{'id': '270', 'type': 'integer', 'children': [], 'value': '0'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'coordinates'}
def coordinate(self, panes=[], index=0): y = 0 for i, element in enumerate(self.panes): x = 0 if isinstance(element, list): current_height = 0 for j, pane in enumerate(element): if pane.hidden: continue current_width = pane.width current_height = pane.height upper = ((y, x), (y, x+current_width)) lower = ((y+(current_height if current_height > 1 else 0), x), (y+(current_height if current_height > 1 else 0), x+current_width)) pane.coords = [upper, lower] x += current_width y += (current_height+1 if current_height > 1 else 1) else: if element.hidden: continue current_width = element.width current_height = element.height upper = ((y, x), (y, x+current_width)) lower = ((y+(current_height if current_height > 1 else 0), x), (y+(current_height if current_height > 1 else 0), x+current_width)) element.coords = [upper, lower] y += (current_height+1 if current_height > 1 else 1) if self.debug: coordinates = "Coordinates: " + str([p.coords for p in self]) if len(coordinates) > self.width: coordinates = coordinates[:self.width - 3] coordinates += '...' self.addstr(self.height-3, 0, coordinates)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_MakePackagePages'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'showprivate'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'nested'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'showinh'},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '74', '86', '96', '142', '149', '153', '157', '271', '382', '400', '412']},{'id': '16', 'type': 'function_definition', 'children': ['17', '18', '20']},{'id': '17', 'type': 'function_name', 'children': [], 'value': 'checkNoNested'},{'id': '18', 'type': 'parameters', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '20', 'type': 'block', 'children': ['21', '34', '46', '62', '72']},{'id': '21', 'type': 'try_statement', 'children': ['22', '29']},{'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': 'all'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '28', 'type': 'identifier', 'children': [], 'value': '__all__'},{'id': '29', 'type': 'except_clause', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'return_statement', 'children': ['33']},{'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': 'mems'},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'getmembers'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'ismodule'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'mems'},{'id': '49', 'type': 'list_comprehension', 'children': ['50', '51', '54']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '51', 'type': 'for_in_clause', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'mems'},{'id': '54', 'type': 'if_clause', 'children': ['55']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '59'], 'value': 'in'},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '58', 'type': 'integer', 'children': [], 'value': '0'},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '61', 'type': 'identifier', 'children': [], 'value': '__all__'},{'id': '62', 'type': 'if_statement', 'children': ['63', '69']},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '68'], 'value': '>'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'mems'},{'id': '68', 'type': 'integer', 'children': [], 'value': '0'},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'return_statement', 'children': ['71']},{'id': '71', 'type': 'False', 'children': []},{'id': '72', 'type': 'return_statement', 'children': ['73']},{'id': '73', 'type': 'True', 'children': []},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'getmembers'},{'id': '81', 'type': 'argument_list', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'ismodule'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '92']},{'id': '88', 'type': 'pattern_list', 'children': ['89', '90', '91']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'nmods'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'pvt'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'npkgs'},{'id': '92', 'type': 'expression_list', 'children': ['93', '94', '95']},{'id': '93', 'type': 'list', 'children': [], 'value': '[]'},{'id': '94', 'type': 'list', 'children': [], 'value': '[]'},{'id': '95', 'type': 'list', 'children': [], 'value': '[]'},{'id': '96', 'type': 'for_statement', 'children': ['97', '98', '99']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'mods'},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'if_statement', 'children': ['101', '107', '133']},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'checkNoNested'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'subscript', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '106', 'type': 'integer', 'children': [], 'value': '1'},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'if_statement', 'children': ['109', '116', '124']},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '115'], 'value': '=='},{'id': '110', 'type': 'subscript', 'children': ['111', '114']},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '113', 'type': 'integer', 'children': [], 'value': '0'},{'id': '114', 'type': 'integer', 'children': [], 'value': '0'},{'id': '115', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'pvt'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '124', 'type': 'else_clause', 'children': ['125']},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'nmods'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'mod'},{'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': 'npkgs'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '142', 'type': 'if_statement', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'showprivate'},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'augmented_assignment', 'children': ['147', '148'], 'value': '+='},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'nmods'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'pvt'},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '152', 'type': 'list', 'children': [], 'value': '[]'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'ignore'},{'id': '156', 'type': 'list', 'children': [], 'value': '[]'},{'id': '157', 'type': 'for_statement', 'children': ['158', '159', '160']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'pkg'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'npkgs'},{'id': '160', 'type': 'block', 'children': ['161', '192', '209', '216', '227', '247']},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'pt'},{'id': '164', 'type': 'binary_operator', 'children': ['165', '166'], 'value': '%'},{'id': '165', 'type': 'string', 'children': [], 'value': "'%s/%s/%s'"},{'id': '166', 'type': 'tuple', 'children': ['167', '170', '179']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '170', 'type': 'call', 'children': ['171', '176']},{'id': '171', 'type': 'attribute', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '174', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '176', 'type': 'argument_list', 'children': ['177', '178']},{'id': '177', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '178', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '179', 'type': 'subscript', 'children': ['180', '190']},{'id': '180', 'type': 'call', 'children': ['181', '188']},{'id': '181', 'type': 'attribute', 'children': ['182', '187']},{'id': '182', 'type': 'attribute', 'children': ['183', '186']},{'id': '183', 'type': 'subscript', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'pkg'},{'id': '185', 'type': 'integer', 'children': [], 'value': '1'},{'id': '186', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '190', 'type': 'unary_operator', 'children': ['191'], 'value': '-'},{'id': '191', 'type': 'integer', 'children': [], 'value': '1'},{'id': '192', 'type': 'if_statement', 'children': ['193', '201']},{'id': '193', 'type': 'call', 'children': ['194', '199']},{'id': '194', 'type': 'attribute', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'pt'},{'id': '201', 'type': 'block', 'children': ['202']},{'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': 'shutil'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'rmtree'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'pt'},{'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': 'os'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'makedirs'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'pt'},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'augmented_assignment', 'children': ['218', '219'], 'value': '+='},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'ignore'},{'id': '219', 'type': 'call', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'getmembers'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'subscript', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'pkg'},{'id': '226', 'type': 'integer', 'children': [], 'value': '1'},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'assignment', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '230', 'type': 'call', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '233', 'type': 'identifier', 'children': [], 'value': '_MakePackagePages'},{'id': '234', 'type': 'argument_list', 'children': ['235', '238', '241', '244']},{'id': '235', 'type': 'subscript', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'pkg'},{'id': '237', 'type': 'integer', 'children': [], 'value': '1'},{'id': '238', 'type': 'keyword_argument', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'showprivate'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'showprivate'},{'id': '241', 'type': 'keyword_argument', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'nested'},{'id': '243', 'type': 'True', 'children': []},{'id': '244', 'type': 'keyword_argument', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'showinh'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'showinh'},{'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': 'files'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '252', 'type': 'argument_list', 'children': ['253']},{'id': '253', 'type': 'subscript', 'children': ['254', '270']},{'id': '254', 'type': 'call', 'children': ['255', '258']},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '258', 'type': 'argument_list', 'children': ['259']},{'id': '259', 'type': 'binary_operator', 'children': ['260', '269'], 'value': '+'},{'id': '260', 'type': 'call', 'children': ['261', '266']},{'id': '261', 'type': 'attribute', 'children': ['262', '265']},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '264', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '266', 'type': 'argument_list', 'children': ['267', '268']},{'id': '267', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '268', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '269', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '270', 'type': 'integer', 'children': [], 'value': '1'},{'id': '271', 'type': 'if_statement', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'nested'},{'id': '273', 'type': 'block', 'children': ['274', '291', '304', '313', '330', '345', '378']},{'id': '274', 'type': 'try_statement', 'children': ['275', '282']},{'id': '275', 'type': 'block', 'children': ['276']},{'id': '276', 'type': 'expression_statement', 'children': ['277']},{'id': '277', 'type': 'assignment', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '281', 'type': 'identifier', 'children': [], 'value': '__displayname__'},{'id': '282', 'type': 'except_clause', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '284', 'type': 'block', 'children': ['285']},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '288', 'type': 'attribute', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '290', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '291', 'type': 'expression_statement', 'children': ['292']},{'id': '292', 'type': 'assignment', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '294', 'type': 'binary_operator', 'children': ['295', '296'], 'value': '%'},{'id': '295', 'type': 'string', 'children': [], 'value': "r'''\n%s\n%s\n.. toctree::\n :maxdepth: 5\n '''"},{'id': '296', 'type': 'tuple', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '298', 'type': 'binary_operator', 'children': ['299', '300'], 'value': '*'},{'id': '299', 'type': 'string', 'children': [], 'value': "'*'"},{'id': '300', 'type': 'call', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '302', 'type': 'argument_list', 'children': ['303']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '304', 'type': 'expression_statement', 'children': ['305']},{'id': '305', 'type': 'augmented_assignment', 'children': ['306', '307'], 'value': '+='},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '307', 'type': 'call', 'children': ['308', '311']},{'id': '308', 'type': 'attribute', 'children': ['309', '310']},{'id': '309', 'type': 'string', 'children': [], 'value': "'\\n '"},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '311', 'type': 'argument_list', 'children': ['312']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '313', 'type': 'expression_statement', 'children': ['314']},{'id': '314', 'type': 'augmented_assignment', 'children': ['315', '316'], 'value': '+='},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '316', 'type': 'binary_operator', 'children': ['317', '318'], 'value': '+'},{'id': '317', 'type': 'string', 'children': [], 'value': "'\\n '"},{'id': '318', 'type': 'call', 'children': ['319', '322']},{'id': '319', 'type': 'attribute', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '321', 'type': 'identifier', 'children': [], 'value': '_ProduceContent'},{'id': '322', 'type': 'argument_list', 'children': ['323', '324', '327']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'nmods'},{'id': '324', 'type': 'keyword_argument', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'showprivate'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'showprivate'},{'id': '327', 'type': 'keyword_argument', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'showinh'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'showinh'},{'id': '330', 'type': 'expression_statement', 'children': ['331']},{'id': '331', 'type': 'assignment', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'findex'},{'id': '333', 'type': 'binary_operator', 'children': ['334', '335'], 'value': '%'},{'id': '334', 'type': 'string', 'children': [], 'value': "'content/%s/index.rst'"},{'id': '335', 'type': '()', 'children': ['336']},{'id': '336', 'type': 'call', 'children': ['337', '342']},{'id': '337', 'type': 'attribute', 'children': ['338', '341']},{'id': '338', 'type': 'attribute', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '340', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '342', 'type': 'argument_list', 'children': ['343', '344']},{'id': '343', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '344', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '345', 'type': 'with_statement', 'children': ['346', '356']},{'id': '346', 'type': 'with_clause', 'children': ['347']},{'id': '347', 'type': 'with_item', 'children': ['348']},{'id': '348', 'type': 'as_pattern', 'children': ['349', '354']},{'id': '349', 'type': 'call', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '351', 'type': 'argument_list', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'findex'},{'id': '353', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '354', 'type': 'as_pattern_target', 'children': ['355']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '356', 'type': 'block', 'children': ['357', '371']},{'id': '357', 'type': 'if_statement', 'children': ['358', '361']},{'id': '358', 'type': 'attribute', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '360', 'type': 'identifier', 'children': [], 'value': '__doc__'},{'id': '361', 'type': 'block', 'children': ['362']},{'id': '362', 'type': 'expression_statement', 'children': ['363']},{'id': '363', 'type': 'call', 'children': ['364', '367']},{'id': '364', 'type': 'attribute', 'children': ['365', '366']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '367', 'type': 'argument_list', 'children': ['368']},{'id': '368', 'type': 'attribute', 'children': ['369', '370']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '370', 'type': 'identifier', 'children': [], 'value': '__doc__'},{'id': '371', 'type': 'expression_statement', 'children': ['372']},{'id': '372', 'type': 'call', 'children': ['373', '376']},{'id': '373', 'type': 'attribute', 'children': ['374', '375']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '376', 'type': 'argument_list', 'children': ['377']},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '378', 'type': 'return_statement', 'children': ['379']},{'id': '379', 'type': 'binary_operator', 'children': ['380', '381'], 'value': '+'},{'id': '380', 'type': 'string', 'children': [], 'value': "'\\n '"},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'findex'},{'id': '382', 'type': 'expression_statement', 'children': ['383']},{'id': '383', 'type': 'assignment', 'children': ['384', '385']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '385', 'type': 'binary_operator', 'children': ['386', '387'], 'value': '%'},{'id': '386', 'type': 'string', 'children': [], 'value': "'\\n %s/%s/'"},{'id': '387', 'type': 'tuple', 'children': ['388', '391']},{'id': '388', 'type': 'attribute', 'children': ['389', '390']},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '391', 'type': 'call', 'children': ['392', '397']},{'id': '392', 'type': 'attribute', 'children': ['393', '396']},{'id': '393', 'type': 'attribute', 'children': ['394', '395']},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '395', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '397', 'type': 'argument_list', 'children': ['398', '399']},{'id': '398', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '399', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '400', 'type': 'expression_statement', 'children': ['401']},{'id': '401', 'type': 'assignment', 'children': ['402', '403']},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'nmods'},{'id': '403', 'type': 'list_comprehension', 'children': ['404', '405', '408']},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '405', 'type': 'for_in_clause', 'children': ['406', '407']},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'nmods'},{'id': '408', 'type': 'if_clause', 'children': ['409']},{'id': '409', 'type': 'comparison_operator', 'children': ['410', '411'], 'value': 'not'},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'ignore'},{'id': '412', 'type': 'return_statement', 'children': ['413']},{'id': '413', 'type': 'call', 'children': ['414', '417']},{'id': '414', 'type': 'attribute', 'children': ['415', '416']},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '416', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '417', 'type': 'argument_list', 'children': ['418']},{'id': '418', 'type': 'binary_operator', 'children': ['419', '436'], 'value': '+'},{'id': '419', 'type': 'call', 'children': ['420', '434']},{'id': '420', 'type': 'attribute', 'children': ['421', '433']},{'id': '421', 'type': 'call', 'children': ['422', '425']},{'id': '422', 'type': 'attribute', 'children': ['423', '424']},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '424', 'type': 'identifier', 'children': [], 'value': '_ProduceContent'},{'id': '425', 'type': 'argument_list', 'children': ['426', '427', '430']},{'id': '426', 'type': 'identifier', 'children': [], 'value': 'nmods'},{'id': '427', 'type': 'keyword_argument', 'children': ['428', '429']},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'showprivate'},{'id': '429', 'type': 'identifier', 'children': [], 'value': 'showprivate'},{'id': '430', 'type': 'keyword_argument', 'children': ['431', '432']},{'id': '431', 'type': 'identifier', 'children': [], 'value': 'showinh'},{'id': '432', 'type': 'identifier', 'children': [], 'value': 'showinh'},{'id': '433', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '434', 'type': 'argument_list', 'children': ['435']},{'id': '435', 'type': 'string', 'children': [], 'value': "'\\n '"},{'id': '436', 'type': 'identifier', 'children': [], 'value': 'files'}
def _MakePackagePages(self, package, showprivate=False, nested=False, showinh=False): def checkNoNested(mod): try: all = mod.__all__ except AttributeError: return False mems = inspect.getmembers(mod, inspect.ismodule) mems = [m for m in mems if m[0] in mod.__all__] if len(mems) > 0: return False return True mods = inspect.getmembers(package, inspect.ismodule) nmods, pvt, npkgs = [], [], [] for mod in mods: if checkNoNested(mod[1]): if mod[0][0] == '_': pvt.append(mod) else: nmods.append(mod) else: npkgs.append(mod) if showprivate: nmods += pvt files = [] ignore = [] for pkg in npkgs: pt = '%s/%s/%s' % (self.path, package.__name__.replace('.', '/'), pkg[1].__name__.split('.')[-1]) if os.path.exists(pt): shutil.rmtree(pt) os.makedirs(pt) ignore += inspect.getmembers(pkg[1]) f = self._MakePackagePages(pkg[1], showprivate=showprivate, nested=True, showinh=showinh) files.append(f.split(package.__name__.replace('.', '/')+'/')[1]) if nested: try: name = package.__displayname__ except AttributeError: name = package.__name__ index = r''' %s %s .. toctree:: :maxdepth: 5 ''' % (name, '*' * len(name)) index += '\n '.join(files) index += '\n ' + self._ProduceContent(nmods, showprivate=showprivate, showinh=showinh) findex = 'content/%s/index.rst' % (package.__name__.replace('.', '/')) with open(findex, 'w') as f: if package.__doc__: f.write(package.__doc__) f.write(index) return '\n ' + findex names = '\n %s/%s/' % ( self.path, package.__name__.replace('.', '/')) nmods = [m for m in nmods if m not in ignore] return names.join(self._ProduceContent(nmods, showprivate=showprivate, showinh=showinh).split('\n ')+files)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_DocPackageFromTop'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'packages'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'showprivate'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'showinh'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '17', '30', '47', '54', '61', '303']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'appIndex'},{'id': '16', 'type': 'string', 'children': [], 'value': "''"},{'id': '17', 'type': 'if_statement', 'children': ['18', '24']},{'id': '18', 'type': 'not_operator', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '21', 'type': 'argument_list', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'packages'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'list'},{'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': 'packages'},{'id': '28', 'type': 'list', 'children': ['29'], 'value': '[packages]'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'packages'},{'id': '30', 'type': 'if_statement', 'children': ['31', '39']},{'id': '31', 'type': 'call', 'children': ['32', '37']},{'id': '32', 'type': 'attribute', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'string', 'children': [], 'value': "'content'"},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'shutil'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'rmtree'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'string', 'children': [], 'value': "'content'"},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'makedirs'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'string', 'children': [], 'value': "'content'"},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'augmented_assignment', 'children': ['56', '57'], 'value': '+='},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'appIndex'},{'id': '57', 'type': 'binary_operator', 'children': ['58', '59'], 'value': '%'},{'id': '58', 'type': 'string', 'children': [], 'value': "r'''\n.. toctree::\n :maxdepth: 5\n :hidden:\n :caption: %s:\n'''"},{'id': '59', 'type': '()', 'children': ['60']},{'id': '60', 'type': 'string', 'children': [], 'value': "'API Index'"},{'id': '61', 'type': 'for_statement', 'children': ['62', '63', '70']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'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': 'packages'},{'id': '70', 'type': 'block', 'children': ['71', '77', '94', '102', '119', '126', '141', '150', '159', '168', '177', '186', '195', '204', '213', '221', '228', '243', '255', '297']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '74', 'type': 'subscript', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'packages'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '77', 'type': 'try_statement', 'children': ['78', '85']},{'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': 'name'},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '84', 'type': 'identifier', 'children': [], 'value': '__displayname__'},{'id': '85', 'type': 'except_clause', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'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': 'name'},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '93', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '97', 'type': 'binary_operator', 'children': ['98', '99'], 'value': '%'},{'id': '98', 'type': 'string', 'children': [], 'value': "'content/%s'"},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '101', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '102', 'type': 'if_statement', 'children': ['103', '111']},{'id': '103', 'type': 'call', 'children': ['104', '109']},{'id': '104', 'type': 'attribute', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'shutil'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'rmtree'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'makedirs'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'meta'},{'id': '129', 'type': 'binary_operator', 'children': ['130', '131'], 'value': '%'},{'id': '130', 'type': 'string', 'children': [], 'value': "'About %s\\n%s\\n'"},{'id': '131', 'type': 'tuple', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '133', 'type': 'binary_operator', 'children': ['134', '135'], 'value': '*'},{'id': '134', 'type': 'string', 'children': [], 'value': "'='"},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'binary_operator', 'children': ['139', '140'], 'value': '+'},{'id': '139', 'type': 'string', 'children': [], 'value': "'About '"},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'author'},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '146', 'type': 'argument_list', 'children': ['147', '148', '149']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '148', 'type': 'string', 'children': [], 'value': '"__author__"'},{'id': '149', 'type': 'None', 'children': []},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'license'},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '155', 'type': 'argument_list', 'children': ['156', '157', '158']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '157', 'type': 'string', 'children': [], 'value': '"__license__"'},{'id': '158', 'type': 'None', 'children': []},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'copyright'},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '164', 'type': 'argument_list', 'children': ['165', '166', '167']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '166', 'type': 'string', 'children': [], 'value': '"__copyright__"'},{'id': '167', 'type': 'None', 'children': []},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '173', 'type': 'argument_list', 'children': ['174', '175', '176']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '175', 'type': 'string', 'children': [], 'value': '"__version__"'},{'id': '176', 'type': 'None', 'children': []},{'id': '177', 'type': 'if_statement', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'author'},{'id': '179', 'type': 'block', 'children': ['180']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'augmented_assignment', 'children': ['182', '183'], 'value': '+='},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'meta'},{'id': '183', 'type': 'binary_operator', 'children': ['184', '185'], 'value': '%'},{'id': '184', 'type': 'string', 'children': [], 'value': "'\\n* Author: %s'"},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'author'},{'id': '186', 'type': 'if_statement', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'license'},{'id': '188', 'type': 'block', 'children': ['189']},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'augmented_assignment', 'children': ['191', '192'], 'value': '+='},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'meta'},{'id': '192', 'type': 'binary_operator', 'children': ['193', '194'], 'value': '%'},{'id': '193', 'type': 'string', 'children': [], 'value': "'\\n* License: %s'"},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'license'},{'id': '195', 'type': 'if_statement', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'copyright'},{'id': '197', 'type': 'block', 'children': ['198']},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'augmented_assignment', 'children': ['200', '201'], 'value': '+='},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'meta'},{'id': '201', 'type': 'binary_operator', 'children': ['202', '203'], 'value': '%'},{'id': '202', 'type': 'string', 'children': [], 'value': "'\\n* Copyright: %s'"},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'copyright'},{'id': '204', 'type': 'if_statement', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'version'},{'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': 'meta'},{'id': '210', 'type': 'binary_operator', 'children': ['211', '212'], 'value': '%'},{'id': '211', 'type': 'string', 'children': [], 'value': "'\\n* Version: %s'"},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'assignment', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'about'},{'id': '216', 'type': 'binary_operator', 'children': ['217', '218'], 'value': '%'},{'id': '217', 'type': 'string', 'children': [], 'value': "'%s/%s'"},{'id': '218', 'type': 'tuple', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '220', 'type': 'string', 'children': [], 'value': "'index.rst'"},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'this_toc'},{'id': '224', 'type': 'binary_operator', 'children': ['225', '226'], 'value': '%'},{'id': '225', 'type': 'string', 'children': [], 'value': "r'''\n.. toctree::\n :maxdepth: 5\n :caption: %s:\n'''"},{'id': '226', 'type': '()', 'children': ['227']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'augmented_assignment', 'children': ['230', '231'], 'value': '+='},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'this_toc'},{'id': '231', 'type': 'call', 'children': ['232', '235']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '234', 'type': 'identifier', 'children': [], 'value': '_MakePackagePages'},{'id': '235', 'type': 'argument_list', 'children': ['236', '237', '240']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '237', 'type': 'keyword_argument', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'showprivate'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'showprivate'},{'id': '240', 'type': 'keyword_argument', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'showinh'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'showinh'},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'assignment', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'this_toc'},{'id': '246', 'type': 'call', 'children': ['247', '250']},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'this_toc'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '250', 'type': 'argument_list', 'children': ['251', '254']},{'id': '251', 'type': 'binary_operator', 'children': ['252', '253'], 'value': '%'},{'id': '252', 'type': 'string', 'children': [], 'value': "'%s/'"},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '254', 'type': 'string', 'children': [], 'value': "''"},{'id': '255', 'type': 'with_statement', 'children': ['256', '266']},{'id': '256', 'type': 'with_clause', 'children': ['257']},{'id': '257', 'type': 'with_item', 'children': ['258']},{'id': '258', 'type': 'as_pattern', 'children': ['259', '264']},{'id': '259', 'type': 'call', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '261', 'type': 'argument_list', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'about'},{'id': '263', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '264', 'type': 'as_pattern_target', 'children': ['265']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '266', 'type': 'block', 'children': ['267', '276', '290']},{'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': 'f'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '272', 'type': 'argument_list', 'children': ['273']},{'id': '273', 'type': 'binary_operator', 'children': ['274', '275'], 'value': '%'},{'id': '274', 'type': 'string', 'children': [], 'value': "'%s\\n\\n'"},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'meta'},{'id': '276', 'type': 'if_statement', 'children': ['277', '280']},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '279', 'type': 'identifier', 'children': [], 'value': '__doc__'},{'id': '280', 'type': 'block', 'children': ['281']},{'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': 'f'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '286', 'type': 'argument_list', 'children': ['287']},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '289', 'type': 'identifier', 'children': [], 'value': '__doc__'},{'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': 'f'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '295', 'type': 'argument_list', 'children': ['296']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'this_toc'},{'id': '297', 'type': 'expression_statement', 'children': ['298']},{'id': '298', 'type': 'augmented_assignment', 'children': ['299', '300'], 'value': '+='},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'appIndex'},{'id': '300', 'type': 'binary_operator', 'children': ['301', '302'], 'value': '%'},{'id': '301', 'type': 'string', 'children': [], 'value': "'\\n %s'"},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'about'},{'id': '303', 'type': 'return_statement', 'children': ['304']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'appIndex'}
def _DocPackageFromTop(self, packages, showprivate=False, showinh=False): appIndex = '' if not isinstance(packages, list): packages = [packages] if os.path.exists('content'): shutil.rmtree('content') os.makedirs('content') appIndex += r''' .. toctree:: :maxdepth: 5 :hidden: :caption: %s: ''' % ('API Index') for i in range(len(packages)): package = packages[i] try: name = package.__displayname__ except AttributeError: name = package.__name__ path = 'content/%s' % package.__name__ if os.path.exists(path): shutil.rmtree(path) os.makedirs(path) meta = 'About %s\n%s\n' % (name, '='*len('About ' + name)) author = getattr(package, "__author__", None) license = getattr(package, "__license__", None) copyright = getattr(package, "__copyright__", None) version = getattr(package, "__version__", None) if author: meta += '\n* Author: %s' % author if license: meta += '\n* License: %s' % license if copyright: meta += '\n* Copyright: %s' % copyright if version: meta += '\n* Version: %s' % version about = '%s/%s' % (path, 'index.rst') this_toc = r''' .. toctree:: :maxdepth: 5 :caption: %s: ''' % (name) this_toc += self._MakePackagePages(package, showprivate=showprivate, showinh=showinh) this_toc = this_toc.replace('%s/' % path, '') with open(about, 'w') as f: f.write('%s\n\n' % meta) if package.__doc__: f.write(package.__doc__) f.write(this_toc) appIndex += '\n %s' % about return appIndex
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'cmd'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '7', 'type': 'block', 'children': ['8', '27', '40', '81', '93', '97', '101', '163', '178']},{'id': '8', 'type': 'if_statement', 'children': ['9', '20']},{'id': '9', 'type': 'not_operator', 'children': ['10']},{'id': '10', 'type': 'call', 'children': ['11', '18']},{'id': '11', 'type': 'attribute', 'children': ['12', '17']},{'id': '12', 'type': 'subscript', 'children': ['13', '16']},{'id': '13', 'type': 'subscript', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '15', 'type': 'string', 'children': [], 'value': "'config'"},{'id': '16', 'type': 'string', 'children': [], 'value': "'feature'"},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'getboolean'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'string', 'children': [], 'value': "'hooks'"},{'id': '20', 'type': 'block', 'children': ['21', '26']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'string', 'children': [], 'value': '"Hooks are disabled, and this command depends on hooks. Please contact the bot admin(s)."'},{'id': '26', 'type': 'return_statement', 'children': []},{'id': '27', 'type': 'if_statement', 'children': ['28', '33']},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '32'], 'value': '=='},{'id': '29', 'type': 'subscript', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '31', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '32', 'type': 'string', 'children': [], 'value': "'privmsg'"},{'id': '33', 'type': 'block', 'children': ['34', '39']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'string', 'children': [], 'value': '"Note-passing should be done in public."'},{'id': '39', 'type': 'return_statement', 'children': []},{'id': '40', 'type': 'try_statement', 'children': ['41', '72']},{'id': '41', 'type': 'block', 'children': ['42', '55']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '47']},{'id': '44', 'type': 'pattern_list', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'note'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'maxsplit'},{'id': '54', 'type': 'integer', 'children': [], 'value': '1'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'nicks'},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '60', 'type': 'generator_expression', 'children': ['61', '62', '70']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '62', 'type': 'for_in_clause', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'string', 'children': [], 'value': "','"},{'id': '70', 'type': 'if_clause', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '72', 'type': 'except_clause', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '74', 'type': 'block', 'children': ['75', '80']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'string', 'children': [], 'value': '"Not enough arguments."'},{'id': '80', 'type': 'return_statement', 'children': []},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'nickregex'},{'id': '84', 'type': 'binary_operator', 'children': ['85', '92'], 'value': '+'},{'id': '85', 'type': 'subscript', 'children': ['86', '91']},{'id': '86', 'type': 'subscript', 'children': ['87', '90']},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '89', 'type': 'string', 'children': [], 'value': "'config'"},{'id': '90', 'type': 'string', 'children': [], 'value': "'core'"},{'id': '91', 'type': 'string', 'children': [], 'value': "'nickregex'"},{'id': '92', 'type': 'string', 'children': [], 'value': "'+$'"},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'successful_nicks'},{'id': '96', 'type': 'list', 'children': [], 'value': '[]'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'failed_nicks'},{'id': '100', 'type': 'list', 'children': [], 'value': '[]'},{'id': '101', 'type': 'for_statement', 'children': ['102', '103', '104']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'nicks'},{'id': '104', 'type': 'block', 'children': ['105']},{'id': '105', 'type': 'if_statement', 'children': ['106', '113', '154']},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '110', 'type': 'argument_list', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'nickregex'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '113', 'type': 'block', 'children': ['114', '138', '147']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'Notes'},{'id': '119', 'type': 'argument_list', 'children': ['120', '123', '128', '131']},{'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'note'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'note'},{'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'submitter'},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '127', 'type': 'string', 'children': [], 'value': "'nick'"},{'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '131', 'type': 'keyword_argument', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '137', 'type': 'argument_list', 'children': []},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '145']},{'id': '140', 'type': 'attribute', 'children': ['141', '144']},{'id': '141', 'type': 'subscript', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '143', 'type': 'string', 'children': [], 'value': "'db'"},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'row'},{'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': 'successful_nicks'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '154', 'type': 'else_clause', 'children': ['155']},{'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_nicks'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '163', 'type': 'if_statement', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'successful_nicks'},{'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': 'send'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'binary_operator', 'children': ['171', '172'], 'value': '%'},{'id': '171', 'type': 'string', 'children': [], 'value': '"Note left for %s."'},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'string', 'children': [], 'value': '", "'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'successful_nicks'},{'id': '178', 'type': 'if_statement', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'failed_nicks'},{'id': '180', 'type': 'block', 'children': ['181']},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'binary_operator', 'children': ['186', '187'], 'value': '%'},{'id': '186', 'type': 'string', 'children': [], 'value': '"Invalid nick(s): %s."'},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'string', 'children': [], 'value': '", "'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'failed_nicks'}
def cmd(send, msg, args): if not args['config']['feature'].getboolean('hooks'): send("Hooks are disabled, and this command depends on hooks. Please contact the bot admin(s).") return if args['type'] == 'privmsg': send("Note-passing should be done in public.") return try: nick, note = msg.split(maxsplit=1) nicks = set(x for x in nick.split(',') if x) except ValueError: send("Not enough arguments.") return nickregex = args['config']['core']['nickregex'] + '+$' successful_nicks = [] failed_nicks = [] for nick in nicks: if re.match(nickregex, nick): row = Notes(note=note, submitter=args['nick'], nick=nick, time=datetime.now()) args['db'].add(row) successful_nicks.append(nick) else: failed_nicks.append(nick) if successful_nicks: send("Note left for %s." % ", ".join(successful_nicks)) if failed_nicks: send("Invalid nick(s): %s." % ", ".join(failed_nicks))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_category'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '6', 'type': 'block', 'children': ['7', '9']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'string', 'children': [], 'value': "'''\n Add unicode category to set\n Unicode categories are strings like 'Ll', 'Lu', 'Nd', etc.\n See `unicodedata.category()`\n '''"},{'id': '9', 'type': 'if_statement', 'children': ['10', '15', '22', '37', '69', '103', '145']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': '=='},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'sre'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'CATEGORY_DIGIT'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'augmented_assignment', 'children': ['18', '21'], 'value': '|='},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_categories'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'UNICODE_DIGIT_CATEGORIES'},{'id': '22', 'type': 'elif_clause', 'children': ['23', '28']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': '=='},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sre'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'CATEGORY_NOT_DIGIT'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'augmented_assignment', 'children': ['31', '34'], 'value': '|='},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': '_categories'},{'id': '34', 'type': 'binary_operator', 'children': ['35', '36'], 'value': '-'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'UNICODE_CATEGORIES'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'UNICODE_DIGIT_CATEGORIES'},{'id': '37', 'type': 'elif_clause', 'children': ['38', '43']},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': '=='},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'sre'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'CATEGORY_SPACE'},{'id': '43', 'type': 'block', 'children': ['44', '50']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'augmented_assignment', 'children': ['46', '49'], 'value': '|='},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': '_categories'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'UNICODE_SPACE_CATEGORIES'},{'id': '50', 'type': 'for_statement', 'children': ['51', '52', '59']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '52', 'type': '()', 'children': ['53']},{'id': '53', 'type': 'conditional_expression', 'children': ['54', '55', '58'], 'value': 'if'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'UNICODE_SPACE_CHARS'},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '57', 'type': 'identifier', 'children': [], 'value': '_unicode'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'SPACE_CHARS'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '67']},{'id': '62', 'type': 'attribute', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '65', 'type': 'identifier', 'children': [], 'value': '_whitelist_chars'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '69', 'type': 'elif_clause', 'children': ['70', '75']},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': '=='},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'sre'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'CATEGORY_NOT_SPACE'},{'id': '75', 'type': 'block', 'children': ['76', '84']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'augmented_assignment', 'children': ['78', '81'], 'value': '|='},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '80', 'type': 'identifier', 'children': [], 'value': '_categories'},{'id': '81', 'type': 'binary_operator', 'children': ['82', '83'], 'value': '-'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'UNICODE_CATEGORIES'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'UNICODE_SPACE_CATEGORIES'},{'id': '84', 'type': 'for_statement', 'children': ['85', '86', '93']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '86', 'type': '()', 'children': ['87']},{'id': '87', 'type': 'conditional_expression', 'children': ['88', '89', '92'], 'value': 'if'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'UNICODE_SPACE_CHARS'},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': '_unicode'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'SPACE_CHARS'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'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': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': '_blacklist_chars'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '103', 'type': 'elif_clause', 'children': ['104', '109']},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '106'], 'value': '=='},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'sre'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'CATEGORY_WORD'},{'id': '109', 'type': 'block', 'children': ['110', '116', '125']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'augmented_assignment', 'children': ['112', '115'], 'value': '|='},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '114', 'type': 'identifier', 'children': [], 'value': '_categories'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'UNICODE_WORD_CATEGORIES'},{'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': '_whitelist_chars'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'string', 'children': [], 'value': "u'_'"},{'id': '125', 'type': 'if_statement', 'children': ['126', '131']},{'id': '126', 'type': 'boolean_operator', 'children': ['127', '128'], 'value': 'and'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'HAS_WEIRD_WORD_CHARS'},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '130', 'type': 'identifier', 'children': [], 'value': '_unicode'},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'for_statement', 'children': ['133', '134', '135']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'UNICODE_WEIRD_NONWORD_CHARS'},{'id': '135', 'type': 'block', 'children': ['136']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'call', 'children': ['138', '143']},{'id': '138', 'type': 'attribute', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '141', 'type': 'identifier', 'children': [], 'value': '_blacklist_chars'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '145', 'type': 'elif_clause', 'children': ['146', '151']},{'id': '146', 'type': 'comparison_operator', 'children': ['147', '148'], 'value': '=='},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'sre'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'CATEGORY_NOT_WORD'},{'id': '151', 'type': 'block', 'children': ['152', '160', '169']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'augmented_assignment', 'children': ['154', '157'], 'value': '|='},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '156', 'type': 'identifier', 'children': [], 'value': '_categories'},{'id': '157', 'type': 'binary_operator', 'children': ['158', '159'], 'value': '-'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'UNICODE_CATEGORIES'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'UNICODE_WORD_CATEGORIES'},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'call', 'children': ['162', '167']},{'id': '162', 'type': 'attribute', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '165', 'type': 'identifier', 'children': [], 'value': '_blacklist_chars'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'string', 'children': [], 'value': "u'_'"},{'id': '169', 'type': 'if_statement', 'children': ['170', '175']},{'id': '170', 'type': 'boolean_operator', 'children': ['171', '172'], 'value': 'and'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'HAS_WEIRD_WORD_CHARS'},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '174', 'type': 'identifier', 'children': [], 'value': '_unicode'},{'id': '175', 'type': 'block', 'children': ['176']},{'id': '176', 'type': 'for_statement', 'children': ['177', '178', '179']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'UNICODE_WEIRD_NONWORD_CHARS'},{'id': '179', 'type': 'block', 'children': ['180']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'call', 'children': ['182', '187']},{'id': '182', 'type': 'attribute', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '185', 'type': 'identifier', 'children': [], 'value': '_whitelist_chars'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'c'}
def add_category(self, category): ''' Add unicode category to set Unicode categories are strings like 'Ll', 'Lu', 'Nd', etc. See `unicodedata.category()` ''' if category == sre.CATEGORY_DIGIT: self._categories |= UNICODE_DIGIT_CATEGORIES elif category == sre.CATEGORY_NOT_DIGIT: self._categories |= UNICODE_CATEGORIES - UNICODE_DIGIT_CATEGORIES elif category == sre.CATEGORY_SPACE: self._categories |= UNICODE_SPACE_CATEGORIES for c in (UNICODE_SPACE_CHARS if self._unicode else SPACE_CHARS): self._whitelist_chars.add(c) elif category == sre.CATEGORY_NOT_SPACE: self._categories |= UNICODE_CATEGORIES - UNICODE_SPACE_CATEGORIES for c in (UNICODE_SPACE_CHARS if self._unicode else SPACE_CHARS): self._blacklist_chars.add(c) elif category == sre.CATEGORY_WORD: self._categories |= UNICODE_WORD_CATEGORIES self._whitelist_chars.add(u'_') if HAS_WEIRD_WORD_CHARS and self._unicode: for c in UNICODE_WEIRD_NONWORD_CHARS: self._blacklist_chars.add(c) elif category == sre.CATEGORY_NOT_WORD: self._categories |= UNICODE_CATEGORIES - UNICODE_WORD_CATEGORIES self._blacklist_chars.add(u'_') if HAS_WEIRD_WORD_CHARS and self._unicode: for c in UNICODE_WEIRD_NONWORD_CHARS: self._whitelist_chars.add(c)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_estimate_free'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '16', '32', '40', '47', '60', '67', '80', '94', '102', '114', '120']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'capacity_deferred'},{'id': '9', 'type': 'call', 'children': ['10', '15']},{'id': '10', 'type': 'attribute', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'total_capacity'},{'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': 'open_tasks_deferred'},{'id': '19', 'type': 'call', 'children': ['20', '25']},{'id': '20', 'type': 'attribute', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'tasks'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '28', 'type': 'list', 'children': ['29'], 'value': '[task_states.OPEN]'},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'task_states'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'OPEN'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'avg_delta_deferred'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'estimate_duration'},{'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': 'deferreds'},{'id': '43', 'type': 'list', 'children': ['44', '45', '46'], 'value': '[capacity_deferred,\n open_tasks_deferred,\n avg_delta_deferred]'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'capacity_deferred'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'open_tasks_deferred'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'avg_delta_deferred'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '50', 'type': 'yield', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'defer'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'gatherResults'},{'id': '55', 'type': 'argument_list', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'deferreds'},{'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'consumeErrors'},{'id': '59', 'type': 'True', 'children': []},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '66']},{'id': '62', 'type': 'pattern_list', 'children': ['63', '64', '65']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'capacity'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'open_tasks'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'avg_delta'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'open_weight'},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'list_comprehension', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'weight'},{'id': '77', 'type': 'for_in_clause', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'open_tasks'},{'id': '80', 'type': 'if_statement', 'children': ['81', '84']},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': '>='},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'open_weight'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'capacity'},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'raise_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'binary_operator', 'children': ['90', '91'], 'value': '%'},{'id': '90', 'type': 'string', 'children': [], 'value': "'channel %d is at capacity'"},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'channel_id'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '97', 'type': 'binary_operator', 'children': ['98', '101'], 'value': '+'},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'created'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'SLEEPTIME'},{'id': '102', 'type': 'if_statement', 'children': ['103', '106']},{'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': 'is'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'avg_delta'},{'id': '105', 'type': 'None', 'children': []},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'defer'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'returnValue'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'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': 'est_completion'},{'id': '117', 'type': 'binary_operator', 'children': ['118', '119'], 'value': '+'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'avg_delta'},{'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': 'defer'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'returnValue'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'est_completion'}
def _estimate_free(self): capacity_deferred = self.channel.total_capacity() open_tasks_deferred = self.channel.tasks(state=[task_states.OPEN]) avg_delta_deferred = self.estimate_duration() deferreds = [capacity_deferred, open_tasks_deferred, avg_delta_deferred] results = yield defer.gatherResults(deferreds, consumeErrors=True) capacity, open_tasks, avg_delta = results open_weight = sum([task.weight for task in open_tasks]) if open_weight >= capacity: raise NotImplementedError('channel %d is at capacity' % self.channel_id) start_time = self.created + SLEEPTIME if avg_delta is None: defer.returnValue(None) est_completion = start_time + avg_delta defer.returnValue(est_completion)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'package'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '21', '37', '52', '67', '75', '82', '164']},{'id': '6', 'type': 'if_statement', 'children': ['7', '12']},{'id': '7', 'type': 'comparison_operator', 'children': ['8', '11'], 'value': '=='},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '11', 'type': 'string', 'children': [], 'value': "'buildNotification'"},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'return_statement', 'children': ['14']},{'id': '14', 'type': 'subscript', 'children': ['15', '20']},{'id': '15', 'type': 'subscript', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '19', 'type': 'integer', 'children': [], 'value': '1'},{'id': '20', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '21', 'type': 'if_statement', 'children': ['22', '30']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '26'], 'value': 'in'},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '26', 'type': 'tuple', 'children': ['27', '28', '29']},{'id': '27', 'type': 'string', 'children': [], 'value': "'createImage'"},{'id': '28', 'type': 'string', 'children': [], 'value': "'image'"},{'id': '29', 'type': 'string', 'children': [], 'value': "'livecd'"},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'return_statement', 'children': ['32']},{'id': '32', 'type': 'subscript', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '36', 'type': 'integer', 'children': [], 'value': '0'},{'id': '37', 'type': 'if_statement', 'children': ['38', '43']},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '42'], 'value': '=='},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '42', 'type': 'string', 'children': [], 'value': "'indirectionimage'"},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'return_statement', 'children': ['45']},{'id': '45', 'type': 'subscript', 'children': ['46', '51']},{'id': '46', 'type': 'subscript', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '50', 'type': 'integer', 'children': [], 'value': '0'},{'id': '51', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '52', 'type': 'if_statement', 'children': ['53', '64']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '57'], 'value': 'not'},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '57', 'type': 'tuple', 'children': ['58', '59', '60', '61', '62', '63']},{'id': '58', 'type': 'string', 'children': [], 'value': "'build'"},{'id': '59', 'type': 'string', 'children': [], 'value': "'buildArch'"},{'id': '60', 'type': 'string', 'children': [], 'value': "'buildContainer'"},{'id': '61', 'type': 'string', 'children': [], 'value': "'buildMaven'"},{'id': '62', 'type': 'string', 'children': [], 'value': "'buildSRPMFromSCM'"},{'id': '63', 'type': 'string', 'children': [], 'value': "'maven'"},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'return_statement', 'children': ['66']},{'id': '66', 'type': 'None', 'children': []},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '70', 'type': 'subscript', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '74', 'type': 'integer', 'children': [], 'value': '0'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'urlparse'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '82', 'type': 'if_statement', 'children': ['83', '89', '116']},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'string', 'children': [], 'value': "'.src.rpm'"},{'id': '89', 'type': 'block', 'children': ['90', '101', '114']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'srpm'},{'id': '93', 'type': 'call', 'children': ['94', '99']},{'id': '94', 'type': 'attribute', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '107']},{'id': '103', 'type': 'tuple_pattern', 'children': ['104', '105', '106']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'srpm'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'rsplit'},{'id': '111', 'type': 'argument_list', 'children': ['112', '113']},{'id': '112', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '113', 'type': 'integer', 'children': [], 'value': '2'},{'id': '114', 'type': 'return_statement', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '116', 'type': 'elif_clause', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '120', 'type': 'block', 'children': ['121', '134', '151', '162']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'package'},{'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': 'os'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '134', 'type': 'if_statement', 'children': ['135', '141']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'string', 'children': [], 'value': "'.git'"},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '147', 'type': 'slice', 'children': ['148', '149']},{'id': '148', 'type': 'colon', 'children': []},{'id': '149', 'type': 'unary_operator', 'children': ['150'], 'value': '-'},{'id': '150', 'type': 'integer', 'children': [], 'value': '4'},{'id': '151', 'type': 'if_statement', 'children': ['152', '157']},{'id': '152', 'type': 'comparison_operator', 'children': ['153', '156'], 'value': '=='},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '156', 'type': 'string', 'children': [], 'value': "'buildContainer'"},{'id': '157', 'type': 'block', 'children': ['158']},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'augmented_assignment', 'children': ['160', '161'], 'value': '+='},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '161', 'type': 'string', 'children': [], 'value': "'-container'"},{'id': '162', 'type': 'return_statement', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'package'},{'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', '170'], 'value': '%'},{'id': '169', 'type': 'string', 'children': [], 'value': '\'could not parse source "%s"\''},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'source'}
def package(self): if self.method == 'buildNotification': return self.params[1]['name'] if self.method in ('createImage', 'image', 'livecd'): return self.params[0] if self.method == 'indirectionimage': return self.params[0]['name'] if self.method not in ('build', 'buildArch', 'buildContainer', 'buildMaven', 'buildSRPMFromSCM', 'maven'): return None source = self.params[0] o = urlparse(source) if source.endswith('.src.rpm'): srpm = os.path.basename(source) (name, version, release) = srpm.rsplit('-', 2) return name elif o.scheme: package = os.path.basename(o.path) if package.endswith('.git'): package = package[:-4] if self.method == 'buildContainer': package += '-container' return package raise ValueError('could not parse source "%s"' % source)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'is_admin'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'required_role'},{'id': '9', 'type': 'string', 'children': [], 'value': "'admin'"},{'id': '10', 'type': 'block', 'children': ['11', '17']},{'id': '11', 'type': 'if_statement', 'children': ['12', '14']},{'id': '12', 'type': 'not_operator', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'required_role'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'return_statement', 'children': ['16']},{'id': '16', 'type': 'True', 'children': []},{'id': '17', 'type': 'with_statement', 'children': ['18', '30']},{'id': '18', 'type': 'with_clause', 'children': ['19']},{'id': '19', 'type': 'with_item', 'children': ['20']},{'id': '20', 'type': 'as_pattern', 'children': ['21', '28']},{'id': '21', 'type': 'call', 'children': ['22', '27']},{'id': '22', 'type': 'attribute', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'session_scope'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'as_pattern_target', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '30', 'type': 'block', 'children': ['31', '57', '64', '77', '92']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'admin'},{'id': '34', 'type': 'call', 'children': ['35', '56']},{'id': '35', 'type': 'attribute', 'children': ['36', '55']},{'id': '36', 'type': 'call', 'children': ['37', '47']},{'id': '37', 'type': 'attribute', 'children': ['38', '46']},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'orm'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'Permissions'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '54'], 'value': '=='},{'id': '49', 'type': 'attribute', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'orm'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'Permissions'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '56', 'type': 'argument_list', 'children': []},{'id': '57', 'type': 'if_statement', 'children': ['58', '61']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'is'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'admin'},{'id': '60', 'type': 'None', 'children': []},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'return_statement', 'children': ['63']},{'id': '63', 'type': 'False', 'children': []},{'id': '64', 'type': 'if_statement', 'children': ['65', '74']},{'id': '65', 'type': 'boolean_operator', 'children': ['66', '69'], 'value': 'and'},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': '=='},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'required_role'},{'id': '68', 'type': 'string', 'children': [], 'value': '"owner"'},{'id': '69', 'type': 'comparison_operator', 'children': ['70', '73'], 'value': '!='},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'admin'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'role'},{'id': '73', 'type': 'string', 'children': [], 'value': '"owner"'},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'return_statement', 'children': ['76']},{'id': '76', 'type': 'False', 'children': []},{'id': '77', 'type': 'if_statement', 'children': ['78', '89']},{'id': '78', 'type': 'not_operator', 'children': ['79']},{'id': '79', 'type': 'call', 'children': ['80', '87']},{'id': '80', 'type': 'attribute', 'children': ['81', '86']},{'id': '81', 'type': 'subscript', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '85', 'type': 'string', 'children': [], 'value': "'feature'"},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'getboolean'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'string', 'children': [], 'value': "'nickserv'"},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'return_statement', 'children': ['91']},{'id': '91', 'type': 'True', 'children': []},{'id': '92', 'type': 'if_statement', 'children': ['93', '97', '128']},{'id': '93', 'type': 'not_operator', 'children': ['94']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'admin'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'registered'},{'id': '97', 'type': 'block', 'children': ['98', '105', '126']},{'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': 'self'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'update_authstatus'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '105', 'type': 'if_statement', 'children': ['106', '109']},{'id': '106', 'type': 'comparison_operator', 'children': ['107', '108'], 'value': 'is'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '108', 'type': 'None', 'children': []},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '113', 'type': 'argument_list', 'children': ['114', '117']},{'id': '114', 'type': 'binary_operator', 'children': ['115', '116'], 'value': '%'},{'id': '115', 'type': 'string', 'children': [], 'value': '"Unverified admin: %s"'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '119', 'type': 'subscript', 'children': ['120', '125']},{'id': '120', 'type': 'subscript', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '124', 'type': 'string', 'children': [], 'value': "'core'"},{'id': '125', 'type': 'string', 'children': [], 'value': "'channel'"},{'id': '126', 'type': 'return_statement', 'children': ['127']},{'id': '127', 'type': 'False', 'children': []},{'id': '128', 'type': 'else_clause', 'children': ['129']},{'id': '129', 'type': 'block', 'children': ['130', '163']},{'id': '130', 'type': 'if_statement', 'children': ['131', '137']},{'id': '131', 'type': 'not_operator', 'children': ['132']},{'id': '132', 'type': 'subscript', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'features'},{'id': '136', 'type': 'string', 'children': [], 'value': "'account-notify'"},{'id': '137', 'type': 'block', 'children': ['138']},{'id': '138', 'type': 'if_statement', 'children': ['139', '155']},{'id': '139', 'type': 'comparison_operator', 'children': ['140', '149'], 'value': '>'},{'id': '140', 'type': 'binary_operator', 'children': ['141', '146'], 'value': '-'},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '145', 'type': 'argument_list', 'children': []},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'admin'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'timedelta'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'minutes'},{'id': '154', 'type': 'integer', 'children': [], 'value': '5'},{'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': 'self'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'update_authstatus'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '163', 'type': 'return_statement', 'children': ['164']},{'id': '164', 'type': 'True', 'children': []}
def is_admin(self, send, nick, required_role='admin'): if not required_role: return True with self.db.session_scope() as session: admin = session.query(orm.Permissions).filter(orm.Permissions.nick == nick).first() if admin is None: return False if required_role == "owner" and admin.role != "owner": return False if not self.config['feature'].getboolean('nickserv'): return True if not admin.registered: self.update_authstatus(nick) if send is not None: send("Unverified admin: %s" % nick, target=self.config['core']['channel']) return False else: if not self.features['account-notify']: if datetime.now() - admin.time > timedelta(minutes=5): self.update_authstatus(nick) return True
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'do_mode'},{'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': 'msg'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '9', 'type': 'block', 'children': ['10', '21', '84', '138']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'mode_changes'},{'id': '13', 'type': 'call', 'children': ['14', '19']},{'id': '14', 'type': 'attribute', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'irc'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'modes'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'parse_channel_modes'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '21', 'type': 'with_statement', 'children': ['22', '27']},{'id': '22', 'type': 'with_clause', 'children': ['23']},{'id': '23', 'type': 'with_item', 'children': ['24']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'data_lock'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'for_statement', 'children': ['29', '30', '31']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'change'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'mode_changes'},{'id': '31', 'type': 'block', 'children': ['32', '58']},{'id': '32', 'type': 'if_statement', 'children': ['33', '38']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '37'], 'value': '=='},{'id': '34', 'type': 'subscript', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'change'},{'id': '36', 'type': 'integer', 'children': [], 'value': '1'},{'id': '37', 'type': 'string', 'children': [], 'value': "'v'"},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '50']},{'id': '41', 'type': 'subscript', 'children': ['42', '47']},{'id': '42', 'type': 'subscript', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'voiced'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'change'},{'id': '49', 'type': 'integer', 'children': [], 'value': '2'},{'id': '50', 'type': 'conditional_expression', 'children': ['51', '52', '57'], 'value': 'if'},{'id': '51', 'type': 'True', 'children': []},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '56'], 'value': '=='},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'change'},{'id': '55', 'type': 'integer', 'children': [], 'value': '0'},{'id': '56', 'type': 'string', 'children': [], 'value': "'+'"},{'id': '57', 'type': 'False', 'children': []},{'id': '58', 'type': 'if_statement', 'children': ['59', '64']},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '63'], 'value': '=='},{'id': '60', 'type': 'subscript', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'change'},{'id': '62', 'type': 'integer', 'children': [], 'value': '1'},{'id': '63', 'type': 'string', 'children': [], 'value': "'o'"},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '76']},{'id': '67', 'type': 'subscript', 'children': ['68', '73']},{'id': '68', 'type': 'subscript', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'opers'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '73', 'type': 'subscript', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'change'},{'id': '75', 'type': 'integer', 'children': [], 'value': '2'},{'id': '76', 'type': 'conditional_expression', 'children': ['77', '78', '83'], 'value': 'if'},{'id': '77', 'type': 'True', 'children': []},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '82'], 'value': '=='},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'change'},{'id': '81', 'type': 'integer', 'children': [], 'value': '0'},{'id': '82', 'type': 'string', 'children': [], 'value': "'+'"},{'id': '83', 'type': 'False', 'children': []},{'id': '84', 'type': 'if_statement', 'children': ['85', '97']},{'id': '85', 'type': 'list_comprehension', 'children': ['86', '87', '90']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '87', 'type': 'for_in_clause', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'mode_changes'},{'id': '90', 'type': 'if_clause', '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': 'check_mode'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '97', 'type': 'block', 'children': ['98', '108']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '101', 'type': 'argument_list', 'children': ['102', '105']},{'id': '102', 'type': 'binary_operator', 'children': ['103', '104'], 'value': '%'},{'id': '103', 'type': 'string', 'children': [], 'value': '"%s: :("'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '108', 'type': 'if_statement', 'children': ['109', '117']},{'id': '109', 'type': 'not_operator', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'is_admin'},{'id': '114', 'type': 'argument_list', 'children': ['115', '116']},{'id': '115', 'type': 'None', 'children': []},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '117', 'type': 'block', 'children': ['118', '128']},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '121', 'type': 'argument_list', 'children': ['122', '125']},{'id': '122', 'type': 'binary_operator', 'children': ['123', '124'], 'value': '%'},{'id': '123', 'type': 'string', 'children': [], 'value': '"OP %s"'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '127', 'type': 'string', 'children': [], 'value': "'ChanServ'"},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '131', 'type': 'argument_list', 'children': ['132', '135']},{'id': '132', 'type': 'binary_operator', 'children': ['133', '134'], 'value': '%'},{'id': '133', 'type': 'string', 'children': [], 'value': '"UNBAN %s"'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '135', 'type': 'keyword_argument', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '137', 'type': 'string', 'children': [], 'value': "'ChanServ'"},{'id': '138', 'type': 'if_statement', 'children': ['139', '147']},{'id': '139', 'type': 'comparison_operator', 'children': ['140', '146'], 'value': '>'},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'guarded'},{'id': '146', 'type': 'integer', 'children': [], 'value': '0'},{'id': '147', 'type': 'block', 'children': ['148', '161', '171']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'regex'},{'id': '151', 'type': 'binary_operator', 'children': ['152', '153'], 'value': '%'},{'id': '152', 'type': 'string', 'children': [], 'value': 'r"(.*(-v|-o|\\+q|\\+b)[^ ]*) (%s)"'},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'string', 'children': [], 'value': '"|"'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'guarded'},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '168', 'type': 'argument_list', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'regex'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '171', 'type': 'if_statement', 'children': ['172', '188']},{'id': '172', 'type': 'boolean_operator', 'children': ['173', '174'], 'value': 'and'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '174', 'type': 'comparison_operator', 'children': ['175', '176'], 'value': 'not'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '176', 'type': 'list', 'children': ['177', '183'], 'value': '[match.group(3), self.connection.real_nickname]'},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'integer', 'children': [], 'value': '3'},{'id': '183', 'type': 'attribute', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'real_nickname'},{'id': '188', 'type': 'block', 'children': ['189', '209', '219']},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'modestring'},{'id': '192', 'type': 'binary_operator', 'children': ['193', '194'], 'value': '%'},{'id': '193', 'type': 'string', 'children': [], 'value': '"+voe-qb %s"'},{'id': '194', 'type': '()', 'children': ['195']},{'id': '195', 'type': 'call', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'string', 'children': [], 'value': '" "'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'binary_operator', 'children': ['201', '208'], 'value': '*'},{'id': '201', 'type': 'list', 'children': ['202'], 'value': '[match.group(3)]'},{'id': '202', 'type': 'call', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'integer', 'children': [], 'value': '3'},{'id': '208', 'type': 'integer', 'children': [], 'value': '5'},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '216']},{'id': '211', 'type': 'attribute', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '216', 'type': 'argument_list', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'modestring'},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'call', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '222', 'type': 'argument_list', 'children': ['223', '228']},{'id': '223', 'type': 'binary_operator', 'children': ['224', '225'], 'value': '%'},{'id': '224', 'type': 'string', 'children': [], 'value': "'Mode %s on %s by the guard system'"},{'id': '225', 'type': 'tuple', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'modestring'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '228', 'type': 'keyword_argument', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '230', 'type': 'subscript', 'children': ['231', '236']},{'id': '231', 'type': 'subscript', 'children': ['232', '235']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '235', 'type': 'string', 'children': [], 'value': "'core'"},{'id': '236', 'type': 'string', 'children': [], 'value': "'ctrlchan'"}
def do_mode(self, target, msg, nick, send): mode_changes = irc.modes.parse_channel_modes(msg) with self.data_lock: for change in mode_changes: if change[1] == 'v': self.voiced[target][change[2]] = True if change[0] == '+' else False if change[1] == 'o': self.opers[target][change[2]] = True if change[0] == '+' else False if [x for x in mode_changes if self.check_mode(x)]: send("%s: :(" % nick, target=target) if not self.is_admin(None, nick): send("OP %s" % target, target='ChanServ') send("UNBAN %s" % target, target='ChanServ') if len(self.guarded) > 0: regex = r"(.*(-v|-o|\+q|\+b)[^ ]*) (%s)" % "|".join(self.guarded) match = re.search(regex, msg) if match and nick not in [match.group(3), self.connection.real_nickname]: modestring = "+voe-qb %s" % (" ".join([match.group(3)] * 5)) self.connection.mode(target, modestring) send('Mode %s on %s by the guard system' % (modestring, target), target=self.config['core']['ctrlchan'])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'do_kick'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'slogan'},{'id': '11', 'type': 'True', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '20', '35', '62', '72']},{'id': '13', 'type': 'if_statement', 'children': ['14', '18']},{'id': '14', 'type': 'not_operator', 'children': ['15']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'kick_enabled'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'return_statement', 'children': []},{'id': '20', 'type': 'if_statement', 'children': ['21', '26']},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'not'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'channels'},{'id': '26', 'type': 'block', 'children': ['27', '34']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'binary_operator', 'children': ['32', '33'], 'value': '%'},{'id': '32', 'type': 'string', 'children': [], 'value': '"%s: you\'re lucky, private message kicking hasn\'t been implemented yet."'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '34', 'type': 'return_statement', 'children': []},{'id': '35', 'type': 'with_statement', 'children': ['36', '41']},{'id': '36', 'type': 'with_clause', 'children': ['37']},{'id': '37', 'type': 'with_item', 'children': ['38']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'data_lock'},{'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': 'ops'},{'id': '45', 'type': 'list_comprehension', 'children': ['46', '47', '60']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '47', 'type': 'for_in_clause', 'children': ['48', '51']},{'id': '48', 'type': 'pattern_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '51', 'type': 'call', 'children': ['52', '59']},{'id': '52', 'type': 'attribute', 'children': ['53', '58']},{'id': '53', 'type': 'subscript', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'opers'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '59', 'type': 'argument_list', 'children': []},{'id': '60', 'type': 'if_clause', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'botnick'},{'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': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '70', 'type': 'string', 'children': [], 'value': "'core'"},{'id': '71', 'type': 'string', 'children': [], 'value': "'nick'"},{'id': '72', 'type': 'if_statement', 'children': ['73', '76', '106', '147']},{'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': 'not'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'botnick'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'ops'},{'id': '76', 'type': 'block', 'children': ['77', '86']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'ops'},{'id': '80', 'type': 'conditional_expression', 'children': ['81', '83', '85'], 'value': 'if'},{'id': '81', 'type': 'list', 'children': ['82'], 'value': "['someone']"},{'id': '82', 'type': 'string', 'children': [], 'value': "'someone'"},{'id': '83', 'type': 'not_operator', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'ops'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'ops'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '89', 'type': 'argument_list', 'children': ['90', '103']},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'textutils'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'gen_creffett'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'binary_operator', 'children': ['96', '97'], 'value': '%'},{'id': '96', 'type': 'string', 'children': [], 'value': '"%s: /op the bot"'},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'choice'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'ops'},{'id': '103', 'type': 'keyword_argument', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '106', 'type': 'elif_clause', 'children': ['107', '118']},{'id': '107', 'type': 'boolean_operator', 'children': ['108', '115'], 'value': 'and'},{'id': '108', 'type': 'comparison_operator', 'children': ['109', '114'], 'value': '<'},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '113', 'type': 'argument_list', 'children': []},{'id': '114', 'type': 'float', 'children': [], 'value': '0.01'},{'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': '=='},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '117', 'type': 'string', 'children': [], 'value': '"shutting caps lock off"'},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'if_statement', 'children': ['120', '123', '134']},{'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': 'in'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'ops'},{'id': '123', 'type': 'block', 'children': ['124']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '127', 'type': 'argument_list', 'children': ['128', '131']},{'id': '128', 'type': 'binary_operator', 'children': ['129', '130'], 'value': '%'},{'id': '129', 'type': 'string', 'children': [], 'value': '"%s: HUEHUEHUE GIBE CAPSLOCK PLS I REPORT U"'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '131', 'type': 'keyword_argument', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '134', 'type': 'else_clause', 'children': ['135']},{'id': '135', 'type': 'block', 'children': ['136']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'call', 'children': ['138', '143']},{'id': '138', 'type': 'attribute', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'kick'},{'id': '143', 'type': 'argument_list', 'children': ['144', '145', '146']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '146', 'type': 'string', 'children': [], 'value': '"HUEHUEHUE GIBE CAPSLOCK PLS I REPORT U"'},{'id': '147', 'type': 'else_clause', 'children': ['148']},{'id': '148', 'type': 'block', 'children': ['149', '165']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '152', 'type': 'conditional_expression', 'children': ['153', '163', '164'], 'value': 'if'},{'id': '153', 'type': 'call', 'children': ['154', '162']},{'id': '154', 'type': 'attribute', 'children': ['155', '161']},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'textutils'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'gen_slogan'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '162', 'type': 'argument_list', 'children': []},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'slogan'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '165', 'type': 'if_statement', 'children': ['166', '169', '182']},{'id': '166', 'type': 'comparison_operator', 'children': ['167', '168'], 'value': 'in'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'ops'},{'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': 'send'},{'id': '173', 'type': 'argument_list', 'children': ['174', '179']},{'id': '174', 'type': 'binary_operator', 'children': ['175', '176'], 'value': '%'},{'id': '175', 'type': 'string', 'children': [], 'value': '"%s: %s"'},{'id': '176', 'type': 'tuple', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '179', 'type': 'keyword_argument', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'target'},{'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', '191']},{'id': '186', 'type': 'attribute', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'kick'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193', '194']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'msg'}
def do_kick(self, send, target, nick, msg, slogan=True): if not self.kick_enabled: return if target not in self.channels: send("%s: you're lucky, private message kicking hasn't been implemented yet." % nick) return with self.data_lock: ops = [k for k, v in self.opers[target].items() if v] botnick = self.config['core']['nick'] if botnick not in ops: ops = ['someone'] if not ops else ops send(textutils.gen_creffett("%s: /op the bot" % random.choice(ops)), target=target) elif random.random() < 0.01 and msg == "shutting caps lock off": if nick in ops: send("%s: HUEHUEHUE GIBE CAPSLOCK PLS I REPORT U" % nick, target=target) else: self.connection.kick(target, nick, "HUEHUEHUE GIBE CAPSLOCK PLS I REPORT U") else: msg = textutils.gen_slogan(msg).upper() if slogan else msg if nick in ops: send("%s: %s" % (nick, msg), target=target) else: self.connection.kick(target, nick, msg)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'handle_msg'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '7', 'type': 'block', 'children': ['8', '36', '64', '77', '106', '137', '148', '160', '178', '196', '227', '245', '276', '294', '305', '313', '329', '340']},{'id': '8', 'type': 'if_statement', 'children': ['9', '19', '28']},{'id': '9', 'type': 'comparison_operator', 'children': ['10', '13'], 'value': 'not'},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '13', 'type': 'list', 'children': ['14', '15', '16', '17', '18'], 'value': "['authenticate', 'error', 'join', 'part', 'quit']"},{'id': '14', 'type': 'string', 'children': [], 'value': "'authenticate'"},{'id': '15', 'type': 'string', 'children': [], 'value': "'error'"},{'id': '16', 'type': 'string', 'children': [], 'value': "'join'"},{'id': '17', 'type': 'string', 'children': [], 'value': "'part'"},{'id': '18', 'type': 'string', 'children': [], 'value': "'quit'"},{'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': 'nick'},{'id': '23', 'type': 'attribute', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '28', 'type': 'else_clause', 'children': ['29']},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '36', 'type': 'if_statement', 'children': ['37', '42', '47']},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '41'], 'value': 'is'},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'arguments'},{'id': '41', 'type': 'None', 'children': []},{'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': 'msg'},{'id': '46', 'type': 'string', 'children': [], 'value': '""'},{'id': '47', 'type': 'else_clause', 'children': ['48']},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '52', 'type': 'call', 'children': ['53', '63']},{'id': '53', 'type': 'attribute', 'children': ['54', '62']},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'string', 'children': [], 'value': '" "'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'arguments'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'strip'},{'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': 'target'},{'id': '67', 'type': 'conditional_expression', 'children': ['68', '69', '74'], 'value': 'if'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '69', 'type': 'comparison_operator', 'children': ['70', '73'], 'value': '=='},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '73', 'type': 'string', 'children': [], 'value': "'privmsg'"},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '77', 'type': 'function_definition', 'children': ['78', '79', '90']},{'id': '78', 'type': 'function_name', 'children': [], 'value': 'send'},{'id': '79', 'type': 'parameters', 'children': ['80', '81', '84', '87']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '81', 'type': 'default_parameter', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'mtype'},{'id': '83', 'type': 'string', 'children': [], 'value': "'privmsg'"},{'id': '84', 'type': 'default_parameter', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '87', 'type': 'default_parameter', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'ignore_length'},{'id': '89', 'type': 'False', 'children': []},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '96', 'type': 'argument_list', 'children': ['97', '98', '103', '104', '105']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'target'},{'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': 'connection'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'real_nickname'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'mtype'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'ignore_length'},{'id': '106', 'type': 'if_statement', 'children': ['107', '125']},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '111'], 'value': 'in'},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '111', 'type': 'list', 'children': ['112', '113', '114', '115', '116', '117', '118', '119', '120', '121', '122', '123', '124'], 'value': "[\n 'account', 'authenticate', 'bannedfromchan', 'cap', 'ctcpreply', 'error', 'featurelist', 'nosuchnick', 'nick', 'nicknameinuse',\n 'privnotice', 'welcome', 'whospcrpl'\n ]"},{'id': '112', 'type': 'string', 'children': [], 'value': "'account'"},{'id': '113', 'type': 'string', 'children': [], 'value': "'authenticate'"},{'id': '114', 'type': 'string', 'children': [], 'value': "'bannedfromchan'"},{'id': '115', 'type': 'string', 'children': [], 'value': "'cap'"},{'id': '116', 'type': 'string', 'children': [], 'value': "'ctcpreply'"},{'id': '117', 'type': 'string', 'children': [], 'value': "'error'"},{'id': '118', 'type': 'string', 'children': [], 'value': "'featurelist'"},{'id': '119', 'type': 'string', 'children': [], 'value': "'nosuchnick'"},{'id': '120', 'type': 'string', 'children': [], 'value': "'nick'"},{'id': '121', 'type': 'string', 'children': [], 'value': "'nicknameinuse'"},{'id': '122', 'type': 'string', 'children': [], 'value': "'privnotice'"},{'id': '123', 'type': 'string', 'children': [], 'value': "'welcome'"},{'id': '124', 'type': 'string', 'children': [], 'value': "'whospcrpl'"},{'id': '125', 'type': 'block', 'children': ['126', '136']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'handle_event'},{'id': '131', 'type': 'argument_list', 'children': ['132', '133', '134', '135']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '136', 'type': 'return_statement', 'children': []},{'id': '137', 'type': 'if_statement', 'children': ['138', '146']},{'id': '138', 'type': 'boolean_operator', 'children': ['139', '141'], 'value': 'and'},{'id': '139', 'type': 'not_operator', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '141', 'type': 'comparison_operator', 'children': ['142', '145'], 'value': '!='},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '145', 'type': 'string', 'children': [], 'value': "'join'"},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'return_statement', 'children': []},{'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': 'self'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'do_log'},{'id': '153', 'type': 'argument_list', 'children': ['154', '155', '156', '157']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '160', 'type': 'if_statement', 'children': ['161', '166']},{'id': '161', 'type': 'comparison_operator', 'children': ['162', '165'], 'value': '=='},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '165', 'type': 'string', 'children': [], 'value': "'mode'"},{'id': '166', 'type': 'block', 'children': ['167', '177']},{'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': 'self'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'do_mode'},{'id': '172', 'type': 'argument_list', 'children': ['173', '174', '175', '176']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '177', 'type': 'return_statement', 'children': []},{'id': '178', 'type': 'if_statement', 'children': ['179', '184']},{'id': '179', 'type': 'comparison_operator', 'children': ['180', '183'], 'value': '=='},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '183', 'type': 'string', 'children': [], 'value': "'join'"},{'id': '184', 'type': 'block', 'children': ['185', '195']},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'call', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'handle_join'},{'id': '190', 'type': 'argument_list', 'children': ['191', '192', '193', '194']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '195', 'type': 'return_statement', 'children': []},{'id': '196', 'type': 'if_statement', 'children': ['197', '202']},{'id': '197', 'type': 'comparison_operator', 'children': ['198', '201'], 'value': '=='},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '201', 'type': 'string', 'children': [], 'value': "'part'"},{'id': '202', 'type': 'block', 'children': ['203', '226']},{'id': '203', 'type': 'if_statement', 'children': ['204', '209']},{'id': '204', 'type': 'comparison_operator', 'children': ['205', '206'], 'value': '=='},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'real_nickname'},{'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': 'send'},{'id': '213', 'type': 'argument_list', 'children': ['214', '217']},{'id': '214', 'type': 'binary_operator', 'children': ['215', '216'], 'value': '%'},{'id': '215', 'type': 'string', 'children': [], 'value': '"Parted channel %s"'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '217', 'type': 'keyword_argument', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '219', 'type': 'subscript', 'children': ['220', '225']},{'id': '220', 'type': 'subscript', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '224', 'type': 'string', 'children': [], 'value': "'core'"},{'id': '225', 'type': 'string', 'children': [], 'value': "'ctrlchan'"},{'id': '226', 'type': 'return_statement', 'children': []},{'id': '227', 'type': 'if_statement', 'children': ['228', '233']},{'id': '228', 'type': 'comparison_operator', 'children': ['229', '232'], 'value': '=='},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '232', 'type': 'string', 'children': [], 'value': "'kick'"},{'id': '233', 'type': 'block', 'children': ['234', '244']},{'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': 'self'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'handle_kick'},{'id': '239', 'type': 'argument_list', 'children': ['240', '241', '242', '243']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '244', 'type': 'return_statement', 'children': []},{'id': '245', 'type': 'if_statement', 'children': ['246', '265']},{'id': '246', 'type': 'boolean_operator', 'children': ['247', '258'], 'value': 'and'},{'id': '247', 'type': 'comparison_operator', 'children': ['248', '251'], 'value': '=='},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '251', 'type': 'subscript', 'children': ['252', '257']},{'id': '252', 'type': 'subscript', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '256', 'type': 'string', 'children': [], 'value': "'core'"},{'id': '257', 'type': 'string', 'children': [], 'value': "'ctrlchan'"},{'id': '258', 'type': 'call', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'is_admin'},{'id': '262', 'type': 'argument_list', 'children': ['263', '264']},{'id': '263', 'type': 'None', 'children': []},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '265', 'type': 'block', 'children': ['266']},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'call', 'children': ['268', '271']},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'control'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'handle_ctrlchan'},{'id': '271', 'type': 'argument_list', 'children': ['272', '273', '274', '275']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '276', 'type': 'if_statement', 'children': ['277', '292']},{'id': '277', 'type': 'boolean_operator', 'children': ['278', '284'], 'value': 'and'},{'id': '278', 'type': 'call', 'children': ['279', '282']},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'is_ignored'},{'id': '282', 'type': 'argument_list', 'children': ['283']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '284', 'type': 'not_operator', 'children': ['285']},{'id': '285', 'type': 'call', 'children': ['286', '289']},{'id': '286', 'type': 'attribute', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'is_admin'},{'id': '289', 'type': 'argument_list', 'children': ['290', '291']},{'id': '290', 'type': 'None', 'children': []},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '292', 'type': 'block', 'children': ['293']},{'id': '293', 'type': 'return_statement', 'children': []},{'id': '294', 'type': 'expression_statement', 'children': ['295']},{'id': '295', 'type': 'call', 'children': ['296', '299']},{'id': '296', 'type': 'attribute', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'handle_hooks'},{'id': '299', 'type': 'argument_list', 'children': ['300', '301', '302', '303', '304']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '305', 'type': 'if_statement', 'children': ['306', '311']},{'id': '306', 'type': 'comparison_operator', 'children': ['307', '310'], 'value': '=='},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '310', 'type': 'string', 'children': [], 'value': "'pubnotice'"},{'id': '311', 'type': 'block', 'children': ['312']},{'id': '312', 'type': 'return_statement', 'children': []},{'id': '313', 'type': 'expression_statement', 'children': ['314']},{'id': '314', 'type': 'assignment', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '316', 'type': 'call', 'children': ['317', '320']},{'id': '317', 'type': 'attribute', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'misc'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'get_cmdchar'},{'id': '320', 'type': 'argument_list', 'children': ['321', '324', '325', '326']},{'id': '321', 'type': 'attribute', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '326', 'type': 'attribute', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '329', 'type': 'expression_statement', 'children': ['330']},{'id': '330', 'type': 'assignment', 'children': ['331', '334']},{'id': '331', 'type': 'pattern_list', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'cmd_name'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'cmdargs'},{'id': '334', 'type': 'call', 'children': ['335', '338']},{'id': '335', 'type': 'attribute', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'get_cmd'},{'id': '338', 'type': 'argument_list', 'children': ['339']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '340', 'type': 'if_statement', 'children': ['341', '349', '362']},{'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': 'registry'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'command_registry'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'is_registered'},{'id': '347', 'type': 'argument_list', 'children': ['348']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'cmd_name'},{'id': '349', 'type': 'block', 'children': ['350']},{'id': '350', 'type': 'expression_statement', 'children': ['351']},{'id': '351', 'type': 'call', 'children': ['352', '355']},{'id': '352', 'type': 'attribute', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'run_cmd'},{'id': '355', 'type': 'argument_list', 'children': ['356', '357', '358', '359', '360', '361']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'cmd_name'},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'cmdargs'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '362', 'type': 'elif_clause', 'children': ['363', '366']},{'id': '363', 'type': 'comparison_operator', 'children': ['364', '365'], 'value': '=='},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'cmd_name'},{'id': '365', 'type': 'string', 'children': [], 'value': "'reload'"},{'id': '366', 'type': 'block', 'children': ['367']},{'id': '367', 'type': 'with_statement', 'children': ['368', '380']},{'id': '368', 'type': 'with_clause', 'children': ['369']},{'id': '369', 'type': 'with_item', 'children': ['370']},{'id': '370', 'type': 'as_pattern', 'children': ['371', '378']},{'id': '371', 'type': 'call', 'children': ['372', '377']},{'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': 'db'},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'session_scope'},{'id': '377', 'type': 'argument_list', 'children': []},{'id': '378', 'type': 'as_pattern_target', 'children': ['379']},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '380', 'type': 'block', 'children': ['381']},{'id': '381', 'type': 'if_statement', 'children': ['382', '405']},{'id': '382', 'type': 'call', 'children': ['383', '404']},{'id': '383', 'type': 'attribute', 'children': ['384', '403']},{'id': '384', 'type': 'call', 'children': ['385', '395']},{'id': '385', 'type': 'attribute', 'children': ['386', '394']},{'id': '386', 'type': 'call', 'children': ['387', '390']},{'id': '387', 'type': 'attribute', 'children': ['388', '389']},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '390', 'type': 'argument_list', 'children': ['391']},{'id': '391', 'type': 'attribute', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'orm'},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'Permissions'},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '395', 'type': 'argument_list', 'children': ['396']},{'id': '396', 'type': 'comparison_operator', 'children': ['397', '402'], 'value': '=='},{'id': '397', 'type': 'attribute', 'children': ['398', '401']},{'id': '398', 'type': 'attribute', 'children': ['399', '400']},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'orm'},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'Permissions'},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '404', 'type': 'argument_list', 'children': []},{'id': '405', 'type': 'block', 'children': ['406']},{'id': '406', 'type': 'expression_statement', 'children': ['407']},{'id': '407', 'type': 'call', 'children': ['408', '409']},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '409', 'type': 'argument_list', 'children': ['410']},{'id': '410', 'type': 'string', 'children': [], 'value': '"Aye Aye Capt\'n"'}
def handle_msg(self, c, e): if e.type not in ['authenticate', 'error', 'join', 'part', 'quit']: nick = e.source.nick else: nick = e.source if e.arguments is None: msg = "" else: msg = " ".join(e.arguments).strip() target = nick if e.type == 'privmsg' else e.target def send(msg, mtype='privmsg', target=target, ignore_length=False): self.send(target, self.connection.real_nickname, msg, mtype, ignore_length) if e.type in [ 'account', 'authenticate', 'bannedfromchan', 'cap', 'ctcpreply', 'error', 'featurelist', 'nosuchnick', 'nick', 'nicknameinuse', 'privnotice', 'welcome', 'whospcrpl' ]: self.handle_event(msg, send, c, e) return if not msg and e.type != 'join': return self.do_log(target, nick, msg, e.type) if e.type == 'mode': self.do_mode(target, msg, nick, send) return if e.type == 'join': self.handle_join(c, e, target, send) return if e.type == 'part': if nick == c.real_nickname: send("Parted channel %s" % target, target=self.config['core']['ctrlchan']) return if e.type == 'kick': self.handle_kick(c, e, target, send) return if e.target == self.config['core']['ctrlchan'] and self.is_admin(None, nick): control.handle_ctrlchan(self, msg, nick, send) if self.is_ignored(nick) and not self.is_admin(None, nick): return self.handle_hooks(send, nick, target, e, msg) if e.type == 'pubnotice': return msg = misc.get_cmdchar(self.config, c, msg, e.type) cmd_name, cmdargs = self.get_cmd(msg) if registry.command_registry.is_registered(cmd_name): self.run_cmd(send, nick, target, cmd_name, cmdargs, e) elif cmd_name == 'reload': with self.db.session_scope() as session: if session.query(orm.Permissions).filter(orm.Permissions.nick == nick).count(): send("Aye Aye Capt'n")
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'cmd'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '7', 'type': 'block', 'children': ['8', '14', '33', '67', '77', '87']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '11', 'type': 'subscript', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '13', 'type': 'string', 'children': [], 'value': "'nick'"},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '17', 'type': 'conditional_expression', 'children': ['18', '21', '26'], 'value': 'if'},{'id': '18', 'type': 'subscript', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '20', 'type': 'string', 'children': [], 'value': "'target'"},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '25'], 'value': '!='},{'id': '22', 'type': 'subscript', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '24', 'type': 'string', 'children': [], 'value': "'target'"},{'id': '25', 'type': 'string', 'children': [], 'value': "'private'"},{'id': '26', 'type': 'subscript', 'children': ['27', '32']},{'id': '27', 'type': 'subscript', 'children': ['28', '31']},{'id': '28', 'type': 'subscript', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '30', 'type': 'string', 'children': [], 'value': "'config'"},{'id': '31', 'type': 'string', 'children': [], 'value': "'core'"},{'id': '32', 'type': 'string', 'children': [], 'value': "'channel'"},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '36', 'type': 'dictionary', 'children': ['37', '40', '43', '46', '49', '52', '55', '58', '61', '64']},{'id': '37', 'type': 'pair', 'children': ['38', '39']},{'id': '38', 'type': 'integer', 'children': [], 'value': '1'},{'id': '39', 'type': 'string', 'children': [], 'value': "'Whirr...'"},{'id': '40', 'type': 'pair', 'children': ['41', '42']},{'id': '41', 'type': 'integer', 'children': [], 'value': '2'},{'id': '42', 'type': 'string', 'children': [], 'value': "'Vrrm...'"},{'id': '43', 'type': 'pair', 'children': ['44', '45']},{'id': '44', 'type': 'integer', 'children': [], 'value': '3'},{'id': '45', 'type': 'string', 'children': [], 'value': "'Zzzzhhhh...'"},{'id': '46', 'type': 'pair', 'children': ['47', '48']},{'id': '47', 'type': 'integer', 'children': [], 'value': '4'},{'id': '48', 'type': 'string', 'children': [], 'value': "'SHFRRRRM...'"},{'id': '49', 'type': 'pair', 'children': ['50', '51']},{'id': '50', 'type': 'integer', 'children': [], 'value': '5'},{'id': '51', 'type': 'string', 'children': [], 'value': "'GEEEEZZSH...'"},{'id': '52', 'type': 'pair', 'children': ['53', '54']},{'id': '53', 'type': 'integer', 'children': [], 'value': '6'},{'id': '54', 'type': 'string', 'children': [], 'value': "'PLAAAAIIID...'"},{'id': '55', 'type': 'pair', 'children': ['56', '57']},{'id': '56', 'type': 'integer', 'children': [], 'value': '7'},{'id': '57', 'type': 'string', 'children': [], 'value': "'KKKRRRAAKKKAAKRAKKGGARGHGIZZZZ...'"},{'id': '58', 'type': 'pair', 'children': ['59', '60']},{'id': '59', 'type': 'integer', 'children': [], 'value': '8'},{'id': '60', 'type': 'string', 'children': [], 'value': "'Nuke'"},{'id': '61', 'type': 'pair', 'children': ['62', '63']},{'id': '62', 'type': 'integer', 'children': [], 'value': '9'},{'id': '63', 'type': 'string', 'children': [], 'value': "'nneeeaaaooowwwwww..... BOOOOOSH BLAM KABOOM'"},{'id': '64', 'type': 'pair', 'children': ['65', '66']},{'id': '65', 'type': 'integer', 'children': [], 'value': '10'},{'id': '66', 'type': 'string', 'children': [], 'value': "'ssh [email protected] rm -rf ~%s'"},{'id': '67', 'type': 'if_statement', 'children': ['68', '70']},{'id': '68', 'type': 'not_operator', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '70', 'type': 'block', 'children': ['71', '76']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'string', 'children': [], 'value': "'What to microwave?'"},{'id': '76', 'type': 'return_statement', 'children': []},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '84', 'type': 'argument_list', 'children': ['85', '86']},{'id': '85', 'type': 'string', 'children': [], 'value': "'(-?[0-9]*) (.*)'"},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '87', 'type': 'if_statement', 'children': ['88', '90', '96']},{'id': '88', 'type': 'not_operator', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'string', 'children': [], 'value': "'Power level?'"},{'id': '96', 'type': 'else_clause', 'children': ['97']},{'id': '97', 'type': 'block', 'children': ['98', '110', '119', '130', '141', '205', '211', '234', '239', '256', '268', '282']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'integer', 'children': [], 'value': '1'},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'integer', 'children': [], 'value': '2'},{'id': '119', 'type': 'if_statement', 'children': ['120', '123']},{'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': '>'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '122', 'type': 'integer', 'children': [], 'value': '10'},{'id': '123', 'type': 'block', 'children': ['124', '129']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'string', 'children': [], 'value': "'Aborting to prevent extinction of human race.'"},{'id': '129', 'type': 'return_statement', 'children': []},{'id': '130', 'type': 'if_statement', 'children': ['131', '134']},{'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': '<'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '133', 'type': 'integer', 'children': [], 'value': '1'},{'id': '134', 'type': 'block', 'children': ['135', '140']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'string', 'children': [], 'value': "'Anti-matter not yet implemented.'"},{'id': '140', 'type': 'return_statement', 'children': []},{'id': '141', 'type': 'if_statement', 'children': ['142', '145']},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': '>'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '144', 'type': 'integer', 'children': [], 'value': '7'},{'id': '145', 'type': 'block', 'children': ['146']},{'id': '146', 'type': 'if_statement', 'children': ['147', '154', '161', '173']},{'id': '147', 'type': 'not_operator', 'children': ['148']},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '151', 'type': 'string', 'children': [], 'value': "'is_admin'"},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '154', 'type': 'block', 'children': ['155', '160']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'string', 'children': [], 'value': '"I\'m sorry. Nukes are a admin-only feature"'},{'id': '160', 'type': 'return_statement', 'children': []},{'id': '161', 'type': 'elif_clause', 'children': ['162', '167']},{'id': '162', 'type': 'comparison_operator', 'children': ['163', '164'], 'value': '=='},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '164', 'type': 'subscript', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '166', 'type': 'string', 'children': [], 'value': "'botnick'"},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'string', 'children': [], 'value': '"Sorry, Self-Nuking is disabled pending aquisition of a Lead-Lined Fridge."'},{'id': '173', 'type': 'else_clause', 'children': ['174']},{'id': '174', 'type': 'block', 'children': ['175']},{'id': '175', 'type': 'with_statement', 'children': ['176', '183']},{'id': '176', 'type': 'with_clause', 'children': ['177']},{'id': '177', 'type': 'with_item', 'children': ['178']},{'id': '178', 'type': 'attribute', 'children': ['179', '182']},{'id': '179', 'type': 'subscript', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '181', 'type': 'string', 'children': [], 'value': "'handler'"},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'data_lock'},{'id': '183', 'type': 'block', 'children': ['184']},{'id': '184', 'type': 'if_statement', 'children': ['185', '198']},{'id': '185', 'type': 'comparison_operator', 'children': ['186', '187'], 'value': 'not'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '187', 'type': 'call', 'children': ['188', '197']},{'id': '188', 'type': 'attribute', 'children': ['189', '196']},{'id': '189', 'type': 'subscript', 'children': ['190', '195']},{'id': '190', 'type': 'attribute', 'children': ['191', '194']},{'id': '191', 'type': 'subscript', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '193', 'type': 'string', 'children': [], 'value': "'handler'"},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'channels'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '197', 'type': 'argument_list', 'children': []},{'id': '198', 'type': 'block', 'children': ['199', '204']},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'call', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'string', 'children': [], 'value': '"I\'m sorry. Anonymous Nuking is not allowed"'},{'id': '204', 'type': 'return_statement', 'children': []},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '208', 'type': 'subscript', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '210', 'type': 'integer', 'children': [], 'value': '1'},{'id': '211', 'type': 'for_statement', 'children': ['212', '213', '220']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'i'},{'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': 'integer', 'children': [], 'value': '2'},{'id': '217', 'type': 'binary_operator', 'children': ['218', '219'], 'value': '+'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '219', 'type': 'integer', 'children': [], 'value': '1'},{'id': '220', 'type': 'block', 'children': ['221']},{'id': '221', 'type': 'if_statement', 'children': ['222', '225']},{'id': '222', 'type': 'comparison_operator', 'children': ['223', '224'], 'value': '<'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '224', 'type': 'integer', 'children': [], 'value': '8'},{'id': '225', 'type': 'block', 'children': ['226']},{'id': '226', 'type': 'expression_statement', 'children': ['227']},{'id': '227', 'type': 'augmented_assignment', 'children': ['228', '229'], 'value': '+='},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '229', 'type': 'binary_operator', 'children': ['230', '231'], 'value': '+'},{'id': '230', 'type': 'string', 'children': [], 'value': "' '"},{'id': '231', 'type': 'subscript', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'call', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '237', 'type': 'argument_list', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '239', 'type': 'if_statement', 'children': ['240', '243']},{'id': '240', 'type': 'comparison_operator', 'children': ['241', '242'], 'value': '>='},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '242', 'type': 'integer', 'children': [], 'value': '8'},{'id': '243', 'type': 'block', 'children': ['244']},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'call', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'do_nuke'},{'id': '247', 'type': 'argument_list', 'children': ['248', '253', '254', '255']},{'id': '248', 'type': 'attribute', 'children': ['249', '252']},{'id': '249', 'type': 'subscript', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '251', 'type': 'string', 'children': [], 'value': "'handler'"},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '256', 'type': 'if_statement', 'children': ['257', '260']},{'id': '257', 'type': 'comparison_operator', 'children': ['258', '259'], 'value': '>='},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '259', 'type': 'integer', 'children': [], 'value': '9'},{'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': 'send'},{'id': '264', 'type': 'argument_list', 'children': ['265']},{'id': '265', 'type': 'subscript', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '267', 'type': 'integer', 'children': [], 'value': '9'},{'id': '268', 'type': 'if_statement', 'children': ['269', '272']},{'id': '269', 'type': 'comparison_operator', 'children': ['270', '271'], 'value': '=='},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '271', 'type': 'integer', 'children': [], 'value': '10'},{'id': '272', 'type': 'block', 'children': ['273']},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'call', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '276', 'type': 'argument_list', 'children': ['277']},{'id': '277', 'type': 'binary_operator', 'children': ['278', '281'], 'value': '%'},{'id': '278', 'type': 'subscript', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '280', 'type': 'integer', 'children': [], 'value': '10'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'call', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '285', 'type': 'argument_list', 'children': ['286']},{'id': '286', 'type': 'binary_operator', 'children': ['287', '288'], 'value': '%'},{'id': '287', 'type': 'string', 'children': [], 'value': "'Ding, your %s is ready.'"},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'target'}
def cmd(send, msg, args): nick = args['nick'] channel = args['target'] if args['target'] != 'private' else args['config']['core']['channel'] levels = { 1: 'Whirr...', 2: 'Vrrm...', 3: 'Zzzzhhhh...', 4: 'SHFRRRRM...', 5: 'GEEEEZZSH...', 6: 'PLAAAAIIID...', 7: 'KKKRRRAAKKKAAKRAKKGGARGHGIZZZZ...', 8: 'Nuke', 9: 'nneeeaaaooowwwwww..... BOOOOOSH BLAM KABOOM', 10: 'ssh [email protected] rm -rf ~%s' } if not msg: send('What to microwave?') return match = re.match('(-?[0-9]*) (.*)', msg) if not match: send('Power level?') else: level = int(match.group(1)) target = match.group(2) if level > 10: send('Aborting to prevent extinction of human race.') return if level < 1: send('Anti-matter not yet implemented.') return if level > 7: if not args['is_admin'](nick): send("I'm sorry. Nukes are a admin-only feature") return elif msg == args['botnick']: send("Sorry, Self-Nuking is disabled pending aquisition of a Lead-Lined Fridge.") else: with args['handler'].data_lock: if target not in args['handler'].channels[channel].users(): send("I'm sorry. Anonymous Nuking is not allowed") return msg = levels[1] for i in range(2, level + 1): if i < 8: msg += ' ' + levels[i] send(msg) if level >= 8: do_nuke(args['handler'].connection, nick, target, channel) if level >= 9: send(levels[9]) if level == 10: send(levels[10] % target) send('Ding, your %s is ready.' % target)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'cmdloop'},{'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': 'intro'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '11', '17', '65']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'string', 'children': [], 'value': "''' Override the command loop to handle Ctrl-C. '''"},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'preloop'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'if_statement', 'children': ['18', '25']},{'id': '18', 'type': 'boolean_operator', 'children': ['19', '22'], 'value': 'and'},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'use_rawinput'},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'completekey'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'try_statement', 'children': ['27', '61']},{'id': '27', 'type': 'block', 'children': ['28', '31', '41', '50']},{'id': '28', 'type': 'import_statement', 'children': ['29']},{'id': '29', 'type': 'dotted_name', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'old_completer'},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'get_completer'},{'id': '40', 'type': 'argument_list', 'children': []},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'set_completer'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'complete'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'parse_and_bind'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'binary_operator', 'children': ['57', '60'], 'value': '+'},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'completekey'},{'id': '60', 'type': 'string', 'children': [], 'value': "': complete'"},{'id': '61', 'type': 'except_clause', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'ImportError'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'pass_statement', 'children': []},{'id': '65', 'type': 'try_statement', 'children': ['66', '262']},{'id': '66', 'type': 'block', 'children': ['67', '78', '99', '103', '256']},{'id': '67', 'type': 'if_statement', 'children': ['68', '71']},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'is'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'intro'},{'id': '70', 'type': 'None', 'children': []},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'intro'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'intro'},{'id': '78', 'type': 'if_statement', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'intro'},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '90']},{'id': '85', 'type': 'attribute', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'binary_operator', 'children': ['92', '98'], 'value': '+'},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'intro'},{'id': '98', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '102', 'type': 'None', 'children': []},{'id': '103', 'type': 'while_statement', 'children': ['104', '106']},{'id': '104', 'type': 'not_operator', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '106', 'type': 'block', 'children': ['107', '228', '237', '246']},{'id': '107', 'type': 'if_statement', 'children': ['108', '111', '123']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'cmdqueue'},{'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': 'line'},{'id': '115', 'type': 'call', 'children': ['116', '121']},{'id': '116', 'type': 'attribute', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'cmdqueue'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'integer', 'children': [], 'value': '0'},{'id': '123', 'type': 'else_clause', 'children': ['124']},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'if_statement', 'children': ['126', '129', '175']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'use_rawinput'},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'try_statement', 'children': ['131', '161', '168']},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'if_statement', 'children': ['133', '140', '150']},{'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': 'sys'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'version_info'},{'id': '138', 'type': 'integer', 'children': [], 'value': '0'},{'id': '139', 'type': 'integer', 'children': [], 'value': '2'},{'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': 'line'},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'raw_input'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'prompt'},{'id': '150', 'type': 'else_clause', 'children': ['151']},{'id': '151', 'type': 'block', 'children': ['152']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'input'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'prompt'},{'id': '161', 'type': 'except_clause', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'EOFError'},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '167', 'type': 'string', 'children': [], 'value': "'EOF'"},{'id': '168', 'type': 'except_clause', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'KeyboardInterrupt'},{'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': 'line'},{'id': '174', 'type': 'string', 'children': [], 'value': "'ctrlc'"},{'id': '175', 'type': 'else_clause', 'children': ['176']},{'id': '176', 'type': 'block', 'children': ['177', '188', '196', '206']},{'id': '177', 'type': 'expression_statement', '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': 'self'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'prompt'},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '195']},{'id': '190', 'type': 'attribute', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '195', 'type': 'argument_list', 'children': []},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '199', 'type': 'call', 'children': ['200', '205']},{'id': '200', 'type': 'attribute', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'stdin'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '205', 'type': 'argument_list', 'children': []},{'id': '206', 'type': 'if_statement', 'children': ['207', '212', '217']},{'id': '207', 'type': 'not_operator', 'children': ['208']},{'id': '208', 'type': 'call', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '212', 'type': 'block', 'children': ['213']},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'assignment', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '216', 'type': 'string', 'children': [], 'value': "'EOF'"},{'id': '217', 'type': 'else_clause', 'children': ['218']},{'id': '218', 'type': 'block', 'children': ['219']},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'rstrip'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'string', 'children': [], 'value': "'\\r\\n'"},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '231', 'type': 'call', 'children': ['232', '235']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'precmd'},{'id': '235', 'type': 'argument_list', 'children': ['236']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'assignment', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'stop'},{'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': 'onecmd'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '249', 'type': 'call', 'children': ['250', '253']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'postcmd'},{'id': '253', 'type': 'argument_list', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'call', 'children': ['258', '261']},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'postloop'},{'id': '261', 'type': 'argument_list', 'children': []},{'id': '262', 'type': 'finally_clause', 'children': ['263']},{'id': '263', 'type': 'block', 'children': ['264']},{'id': '264', 'type': 'if_statement', 'children': ['265', '272']},{'id': '265', 'type': 'boolean_operator', 'children': ['266', '269'], 'value': 'and'},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'use_rawinput'},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'completekey'},{'id': '272', 'type': 'block', 'children': ['273']},{'id': '273', 'type': 'try_statement', 'children': ['274', '287']},{'id': '274', 'type': 'block', 'children': ['275', '278']},{'id': '275', 'type': 'import_statement', 'children': ['276']},{'id': '276', 'type': 'dotted_name', 'children': ['277']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'call', 'children': ['280', '283']},{'id': '280', 'type': 'attribute', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'set_completer'},{'id': '283', 'type': 'argument_list', 'children': ['284']},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'old_completer'},{'id': '287', 'type': 'except_clause', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'ImportError'},{'id': '289', 'type': 'block', 'children': ['290']},{'id': '290', 'type': 'pass_statement', 'children': []}
def cmdloop(self, intro=None): ''' Override the command loop to handle Ctrl-C. ''' self.preloop() if self.use_rawinput and self.completekey: try: import readline self.old_completer = readline.get_completer() readline.set_completer(self.complete) readline.parse_and_bind(self.completekey + ': complete') except ImportError: pass try: if intro is not None: self.intro = intro if self.intro: self.stdout.write(str(self.intro)+"\n") stop = None while not stop: if self.cmdqueue: line = self.cmdqueue.pop(0) else: if self.use_rawinput: try: if sys.version_info[0] == 2: line = raw_input(self.prompt) else: line = input(self.prompt) except EOFError: line = 'EOF' except KeyboardInterrupt: line = 'ctrlc' else: self.stdout.write(self.prompt) self.stdout.flush() line = self.stdin.readline() if not len(line): line = 'EOF' else: line = line.rstrip('\r\n') line = self.precmd(line) stop = self.onecmd(line) stop = self.postcmd(stop, line) self.postloop() finally: if self.use_rawinput and self.completekey: try: import readline readline.set_completer(self.old_completer) except ImportError: pass
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'free'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'local_path'},{'id': '6', 'type': 'block', 'children': ['7', '9', '17', '27', '35', '45', '52', '61', '72', '83', '93', '131', '140', '288']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'string', 'children': [], 'value': "'''\n Stop synchronization of local_path\n '''"},{'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', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'get_config'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'st_util'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'find_folder_with_path'},{'id': '24', 'type': 'argument_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'local_path'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'delete_folder'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'local_path'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'pruned'},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'st_util'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'prune_devices'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'config'},{'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': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'set_config'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '52', 'type': 'if_statement', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'pruned'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'restart'},{'id': '60', 'type': 'argument_list', 'children': []},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'dir_config'},{'id': '64', 'type': 'call', 'children': ['65', '70']},{'id': '65', 'type': 'attribute', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'adapter'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'get_dir_config'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'local_path'},{'id': '72', 'type': 'if_statement', 'children': ['73', '75']},{'id': '73', 'type': 'not_operator', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'dir_config'},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'raise_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'custom_errors'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'FileNotInConfig'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'local_path'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'kodrive_config'},{'id': '86', 'type': 'call', 'children': ['87', '92']},{'id': '87', 'type': 'attribute', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'adapter'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'get_config'},{'id': '92', 'type': 'argument_list', 'children': []},{'id': '93', 'type': 'for_statement', 'children': ['94', '95', '98']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'kodrive_config'},{'id': '97', 'type': 'string', 'children': [], 'value': "'directories'"},{'id': '98', 'type': 'block', 'children': ['99', '107']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '102', 'type': 'subscript', 'children': ['103', '106']},{'id': '103', 'type': 'subscript', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'kodrive_config'},{'id': '105', 'type': 'string', 'children': [], 'value': "'directories'"},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '107', 'type': 'if_statement', 'children': ['108', '123']},{'id': '108', 'type': 'comparison_operator', 'children': ['109', '117'], 'value': '=='},{'id': '109', 'type': 'call', 'children': ['110', '115']},{'id': '110', 'type': 'attribute', 'children': ['111', '114']},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '113', 'type': 'string', 'children': [], 'value': "'local_path'"},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'rstrip'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'local_path'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'rstrip'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '123', 'type': 'block', 'children': ['124', '130']},{'id': '124', 'type': 'delete_statement', 'children': ['125']},{'id': '125', 'type': 'subscript', 'children': ['126', '129']},{'id': '126', 'type': 'subscript', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'kodrive_config'},{'id': '128', 'type': 'string', 'children': [], 'value': "'directories'"},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '130', 'type': 'break_statement', 'children': []},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '138']},{'id': '133', 'type': 'attribute', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'adapter'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'set_config'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'kodrive_config'},{'id': '140', 'type': 'if_statement', 'children': ['141', '148']},{'id': '141', 'type': 'boolean_operator', 'children': ['142', '145'], 'value': 'and'},{'id': '142', 'type': 'subscript', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'dir_config'},{'id': '144', 'type': 'string', 'children': [], 'value': "'is_shared'"},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'dir_config'},{'id': '147', 'type': 'string', 'children': [], 'value': "'server'"},{'id': '148', 'type': 'block', 'children': ['149', '155', '161', '184', '213', '221', '233', '241', '249', '262', '272', '279']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'r_api_key'},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'dir_config'},{'id': '154', 'type': 'string', 'children': [], 'value': "'api_key'"},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'r_device_id'},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'dir_config'},{'id': '160', 'type': 'string', 'children': [], 'value': "'device_id'"},{'id': '161', 'type': 'if_statement', 'children': ['162', '165', '172']},{'id': '162', 'type': 'subscript', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'dir_config'},{'id': '164', 'type': 'string', 'children': [], 'value': "'host'"},{'id': '165', 'type': 'block', 'children': ['166']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'dir_config'},{'id': '171', 'type': 'string', 'children': [], 'value': "'host'"},{'id': '172', 'type': 'else_clause', 'children': ['173']},{'id': '173', 'type': 'block', 'children': ['174']},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'devid_to_ip'},{'id': '181', 'type': 'argument_list', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'r_device_id'},{'id': '183', 'type': 'False', 'children': []},{'id': '184', 'type': 'try_statement', 'children': ['185', '205']},{'id': '185', 'type': 'block', 'children': ['186']},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'remote'},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'SyncthingProxy'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193', '194', '195']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'r_device_id'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'r_api_key'},{'id': '195', 'type': 'keyword_argument', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '197', 'type': 'conditional_expression', 'children': ['198', '201', '204'], 'value': 'if'},{'id': '198', 'type': 'subscript', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'dir_config'},{'id': '200', 'type': 'string', 'children': [], 'value': "'port'"},{'id': '201', 'type': 'comparison_operator', 'children': ['202', '203'], 'value': 'in'},{'id': '202', 'type': 'string', 'children': [], 'value': "'port'"},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'dir_config'},{'id': '204', 'type': 'None', 'children': []},{'id': '205', 'type': 'except_clause', 'children': ['206', '210']},{'id': '206', 'type': 'as_pattern', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '208', 'type': 'as_pattern_target', 'children': ['209']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '210', 'type': 'block', 'children': ['211']},{'id': '211', 'type': 'return_statement', 'children': ['212']},{'id': '212', 'type': 'True', 'children': []},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'assignment', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'r_config'},{'id': '216', 'type': 'call', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'remote'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'get_config'},{'id': '220', 'type': 'argument_list', 'children': []},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'r_folder'},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'st_util'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'find_folder_with_path'},{'id': '228', 'type': 'argument_list', 'children': ['229', '232']},{'id': '229', 'type': 'subscript', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'dir_config'},{'id': '231', 'type': 'string', 'children': [], 'value': "'remote_path'"},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'r_config'},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'assignment', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'r_config'},{'id': '236', 'type': 'call', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'remote'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'get_config'},{'id': '240', 'type': 'argument_list', 'children': []},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'assignment', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'self_devid'},{'id': '244', 'type': 'call', 'children': ['245', '248']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'get_device_id'},{'id': '248', 'type': 'argument_list', 'children': []},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'assignment', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'del_device'},{'id': '252', 'type': 'call', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'remote'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'delete_device_from_folder'},{'id': '256', 'type': 'argument_list', 'children': ['257', '260', '261']},{'id': '257', 'type': 'subscript', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'dir_config'},{'id': '259', 'type': 'string', 'children': [], 'value': "'remote_path'"},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'self_devid'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'r_config'},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'assignment', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'pruned'},{'id': '265', 'type': 'call', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'st_util'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'prune_devices'},{'id': '269', 'type': 'argument_list', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'r_folder'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'r_config'},{'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': 'remote'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'set_config'},{'id': '277', 'type': 'argument_list', 'children': ['278']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'r_config'},{'id': '279', 'type': 'if_statement', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'pruned'},{'id': '281', 'type': 'block', 'children': ['282']},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'call', 'children': ['284', '287']},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'remote'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'restart'},{'id': '287', 'type': 'argument_list', 'children': []},{'id': '288', 'type': 'return_statement', 'children': ['289']},{'id': '289', 'type': 'True', 'children': []}
def free(self, local_path): ''' Stop synchronization of local_path ''' config = self.get_config() folder = st_util.find_folder_with_path(local_path, config) self.delete_folder(local_path, config) pruned = st_util.prune_devices(folder, config) self.set_config(config) if pruned: self.restart() dir_config = self.adapter.get_dir_config(local_path) if not dir_config: raise custom_errors.FileNotInConfig(local_path) kodrive_config = self.adapter.get_config() for key in kodrive_config['directories']: d = kodrive_config['directories'][key] if d['local_path'].rstrip('/') == local_path.rstrip('/'): del kodrive_config['directories'][key] break self.adapter.set_config(kodrive_config) if dir_config['is_shared'] and dir_config['server']: r_api_key = dir_config['api_key'] r_device_id = dir_config['device_id'] if dir_config['host']: host = dir_config['host'] else: host = self.devid_to_ip(r_device_id, False) try: remote = SyncthingProxy( r_device_id, host, r_api_key, port=dir_config['port'] if 'port' in dir_config else None ) except Exception as e: return True r_config = remote.get_config() r_folder = st_util.find_folder_with_path( dir_config['remote_path'], r_config ) r_config = remote.get_config() self_devid = self.get_device_id() del_device = remote.delete_device_from_folder( dir_config['remote_path'], self_devid, r_config ) pruned = st_util.prune_devices(r_folder, r_config) remote.set_config(r_config) if pruned: remote.restart() return True
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_package_update_list'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'package_name'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '6', 'type': 'block', 'children': ['7', '18', '25', '33', '37', '41', '45', '49', '53', '57', '61', '65', '69', '284', '310', '321']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'package_version'},{'id': '10', 'type': 'call', 'children': ['11', '16']},{'id': '11', 'type': 'attribute', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'semantic_version'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'Version'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'coerce'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'package_data'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'get_pypi_package_data'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'package_name'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'version_data'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'get_pypi_package_data'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'package_name'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'current_release'},{'id': '36', 'type': 'string', 'children': [], 'value': "''"},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'current_release_license'},{'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': 'latest_release'},{'id': '44', 'type': 'string', 'children': [], 'value': "''"},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'latest_release_license'},{'id': '48', 'type': 'string', 'children': [], 'value': "''"},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'major_updates'},{'id': '52', 'type': 'list', 'children': [], 'value': '[]'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'minor_updates'},{'id': '56', 'type': 'list', 'children': [], 'value': '[]'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'patch_updates'},{'id': '60', 'type': 'list', 'children': [], 'value': '[]'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'pre_releases'},{'id': '64', 'type': 'list', 'children': [], 'value': '[]'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'non_semantic_versions'},{'id': '68', 'type': 'list', 'children': [], 'value': '[]'},{'id': '69', 'type': 'if_statement', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'package_data'},{'id': '71', 'type': 'block', 'children': ['72', '80', '95']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'latest_release'},{'id': '75', 'type': 'subscript', 'children': ['76', '79']},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'package_data'},{'id': '78', 'type': 'string', 'children': [], 'value': "'info'"},{'id': '79', 'type': 'string', 'children': [], 'value': "'version'"},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'latest_release_license'},{'id': '83', 'type': 'conditional_expression', 'children': ['84', '89', '94'], 'value': 'if'},{'id': '84', 'type': 'subscript', 'children': ['85', '88']},{'id': '85', 'type': 'subscript', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'package_data'},{'id': '87', 'type': 'string', 'children': [], 'value': "'info'"},{'id': '88', 'type': 'string', 'children': [], 'value': "'license'"},{'id': '89', 'type': 'subscript', 'children': ['90', '93']},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'package_data'},{'id': '92', 'type': 'string', 'children': [], 'value': "'info'"},{'id': '93', 'type': 'string', 'children': [], 'value': "'license'"},{'id': '94', 'type': 'string', 'children': [], 'value': "''"},{'id': '95', 'type': 'for_statement', 'children': ['96', '99', '106']},{'id': '96', 'type': 'pattern_list', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '99', 'type': 'call', 'children': ['100', '105']},{'id': '100', 'type': 'attribute', 'children': ['101', '104']},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'package_data'},{'id': '103', 'type': 'string', 'children': [], 'value': "'releases'"},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '105', 'type': 'argument_list', 'children': []},{'id': '106', 'type': 'block', 'children': ['107', '114', '118', '135']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'parsed_release'},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'parse'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'upload_time'},{'id': '117', 'type': 'None', 'children': []},{'id': '118', 'type': 'if_statement', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'info'},{'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': 'upload_time'},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'strptime'},{'id': '128', 'type': 'argument_list', 'children': ['129', '134']},{'id': '129', 'type': 'subscript', 'children': ['130', '133']},{'id': '130', 'type': 'subscript', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '132', 'type': 'integer', 'children': [], 'value': '0'},{'id': '133', 'type': 'string', 'children': [], 'value': "'upload_time'"},{'id': '134', 'type': 'string', 'children': [], 'value': '"%Y-%m-%dT%H:%M:%S"'},{'id': '135', 'type': 'try_statement', 'children': ['136', '268']},{'id': '136', 'type': 'block', 'children': ['137', '148']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'release_version'},{'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': 'semantic_version'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'Version'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'coerce'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '148', 'type': 'if_statement', 'children': ['149', '153', '253']},{'id': '149', 'type': 'not_operator', 'children': ['150']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'parsed_release'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'is_prerelease'},{'id': '153', 'type': 'block', 'children': ['154']},{'id': '154', 'type': 'if_statement', 'children': ['155', '169', '183', '218']},{'id': '155', 'type': 'comparison_operator', 'children': ['156', '157'], 'value': 'in'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'release_version'},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'semantic_version'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'Spec'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'binary_operator', 'children': ['163', '164'], 'value': '%'},{'id': '163', 'type': 'string', 'children': [], 'value': '">=%s"'},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'package_version'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'next_major'},{'id': '168', 'type': 'argument_list', 'children': []},{'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': 'major_updates'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'dictionary', 'children': ['177', '180']},{'id': '177', 'type': 'pair', 'children': ['178', '179']},{'id': '178', 'type': 'string', 'children': [], 'value': "'version'"},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '180', 'type': 'pair', 'children': ['181', '182']},{'id': '181', 'type': 'string', 'children': [], 'value': "'upload_time'"},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'upload_time'},{'id': '183', 'type': 'elif_clause', 'children': ['184', '204']},{'id': '184', 'type': 'comparison_operator', 'children': ['185', '186'], 'value': 'in'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'release_version'},{'id': '186', 'type': 'call', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'semantic_version'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'Spec'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'binary_operator', 'children': ['192', '193'], 'value': '%'},{'id': '192', 'type': 'string', 'children': [], 'value': '">=%s,<%s"'},{'id': '193', 'type': 'tuple', 'children': ['194', '199']},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'package_version'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'next_minor'},{'id': '198', 'type': 'argument_list', 'children': []},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'package_version'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'next_major'},{'id': '203', 'type': 'argument_list', 'children': []},{'id': '204', 'type': 'block', 'children': ['205']},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'call', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'minor_updates'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'dictionary', 'children': ['212', '215']},{'id': '212', 'type': 'pair', 'children': ['213', '214']},{'id': '213', 'type': 'string', 'children': [], 'value': "'version'"},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '215', 'type': 'pair', 'children': ['216', '217']},{'id': '216', 'type': 'string', 'children': [], 'value': "'upload_time'"},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'upload_time'},{'id': '218', 'type': 'elif_clause', 'children': ['219', '239']},{'id': '219', 'type': 'comparison_operator', 'children': ['220', '221'], 'value': 'in'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'release_version'},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'semantic_version'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'Spec'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'binary_operator', 'children': ['227', '228'], 'value': '%'},{'id': '227', 'type': 'string', 'children': [], 'value': '">=%s,<%s"'},{'id': '228', 'type': 'tuple', 'children': ['229', '234']},{'id': '229', 'type': 'call', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'package_version'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'next_patch'},{'id': '233', 'type': 'argument_list', 'children': []},{'id': '234', 'type': 'call', 'children': ['235', '238']},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'package_version'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'next_minor'},{'id': '238', 'type': 'argument_list', 'children': []},{'id': '239', 'type': 'block', 'children': ['240']},{'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': 'patch_updates'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '245', 'type': 'argument_list', 'children': ['246']},{'id': '246', 'type': 'dictionary', 'children': ['247', '250']},{'id': '247', 'type': 'pair', 'children': ['248', '249']},{'id': '248', 'type': 'string', 'children': [], 'value': "'version'"},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '250', 'type': 'pair', 'children': ['251', '252']},{'id': '251', 'type': 'string', 'children': [], 'value': "'upload_time'"},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'upload_time'},{'id': '253', 'type': 'else_clause', 'children': ['254']},{'id': '254', 'type': 'block', 'children': ['255']},{'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': 'pre_releases'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '260', 'type': 'argument_list', 'children': ['261']},{'id': '261', 'type': 'dictionary', 'children': ['262', '265']},{'id': '262', 'type': 'pair', 'children': ['263', '264']},{'id': '263', 'type': 'string', 'children': [], 'value': "'version'"},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '265', 'type': 'pair', 'children': ['266', '267']},{'id': '266', 'type': 'string', 'children': [], 'value': "'upload_time'"},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'upload_time'},{'id': '268', 'type': 'except_clause', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '270', 'type': 'block', 'children': ['271']},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'call', 'children': ['273', '276']},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'non_semantic_versions'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '276', 'type': 'argument_list', 'children': ['277']},{'id': '277', 'type': 'dictionary', 'children': ['278', '281']},{'id': '278', 'type': 'pair', 'children': ['279', '280']},{'id': '279', 'type': 'string', 'children': [], 'value': "'version'"},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '281', 'type': 'pair', 'children': ['282', '283']},{'id': '282', 'type': 'string', 'children': [], 'value': "'upload_time'"},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'upload_time'},{'id': '284', 'type': 'if_statement', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'version_data'},{'id': '286', 'type': 'block', 'children': ['287', '295']},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'assignment', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'current_release'},{'id': '290', 'type': 'subscript', 'children': ['291', '294']},{'id': '291', 'type': 'subscript', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'version_data'},{'id': '293', 'type': 'string', 'children': [], 'value': "'info'"},{'id': '294', 'type': 'string', 'children': [], 'value': "'version'"},{'id': '295', 'type': 'expression_statement', 'children': ['296']},{'id': '296', 'type': 'assignment', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'current_release_license'},{'id': '298', 'type': 'conditional_expression', 'children': ['299', '304', '309'], 'value': 'if'},{'id': '299', 'type': 'subscript', 'children': ['300', '303']},{'id': '300', 'type': 'subscript', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'version_data'},{'id': '302', 'type': 'string', 'children': [], 'value': "'info'"},{'id': '303', 'type': 'string', 'children': [], 'value': "'license'"},{'id': '304', 'type': 'subscript', 'children': ['305', '308']},{'id': '305', 'type': 'subscript', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'version_data'},{'id': '307', 'type': 'string', 'children': [], 'value': "'info'"},{'id': '308', 'type': 'string', 'children': [], 'value': "'license'"},{'id': '309', 'type': 'string', 'children': [], 'value': "''"},{'id': '310', 'type': 'expression_statement', 'children': ['311']},{'id': '311', 'type': 'assignment', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'newer_releases'},{'id': '313', 'type': 'call', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '315', 'type': 'argument_list', 'children': ['316']},{'id': '316', 'type': 'binary_operator', 'children': ['317', '320'], 'value': '+'},{'id': '317', 'type': 'binary_operator', 'children': ['318', '319'], 'value': '+'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'major_updates'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'minor_updates'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'patch_updates'},{'id': '321', 'type': 'return_statement', 'children': ['322']},{'id': '322', 'type': 'dictionary', 'children': ['323', '326', '329', '332', '335', '338', '344', '368', '392', '416', '440']},{'id': '323', 'type': 'pair', 'children': ['324', '325']},{'id': '324', 'type': 'string', 'children': [], 'value': "'current_release'"},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'current_release'},{'id': '326', 'type': 'pair', 'children': ['327', '328']},{'id': '327', 'type': 'string', 'children': [], 'value': "'current_release_license'"},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'current_release_license'},{'id': '329', 'type': 'pair', 'children': ['330', '331']},{'id': '330', 'type': 'string', 'children': [], 'value': "'latest_release'"},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'latest_release'},{'id': '332', 'type': 'pair', 'children': ['333', '334']},{'id': '333', 'type': 'string', 'children': [], 'value': "'latest_release_license'"},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'latest_release_license'},{'id': '335', 'type': 'pair', 'children': ['336', '337']},{'id': '336', 'type': 'string', 'children': [], 'value': "'newer_releases'"},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'newer_releases'},{'id': '338', 'type': 'pair', 'children': ['339', '340']},{'id': '339', 'type': 'string', 'children': [], 'value': "'pre_releases'"},{'id': '340', 'type': 'call', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '342', 'type': 'argument_list', 'children': ['343']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'pre_releases'},{'id': '344', 'type': 'pair', 'children': ['345', '346']},{'id': '345', 'type': 'string', 'children': [], 'value': "'major_updates'"},{'id': '346', 'type': 'call', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '348', 'type': 'argument_list', 'children': ['349', '350', '365']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'major_updates'},{'id': '350', 'type': 'keyword_argument', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '352', 'type': 'lambda', 'children': ['353', '355']},{'id': '353', 'type': 'lambda_parameters', 'children': ['354']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '355', 'type': 'call', 'children': ['356', '361']},{'id': '356', 'type': 'attribute', 'children': ['357', '360']},{'id': '357', 'type': 'attribute', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'semantic_version'},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'Version'},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'coerce'},{'id': '361', 'type': 'argument_list', 'children': ['362']},{'id': '362', 'type': 'subscript', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '364', 'type': 'string', 'children': [], 'value': "'version'"},{'id': '365', 'type': 'keyword_argument', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '367', 'type': 'True', 'children': []},{'id': '368', 'type': 'pair', 'children': ['369', '370']},{'id': '369', 'type': 'string', 'children': [], 'value': "'minor_updates'"},{'id': '370', 'type': 'call', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '372', 'type': 'argument_list', 'children': ['373', '374', '389']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'minor_updates'},{'id': '374', 'type': 'keyword_argument', 'children': ['375', '376']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '376', 'type': 'lambda', 'children': ['377', '379']},{'id': '377', 'type': 'lambda_parameters', 'children': ['378']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '379', 'type': 'call', 'children': ['380', '385']},{'id': '380', 'type': 'attribute', 'children': ['381', '384']},{'id': '381', 'type': 'attribute', 'children': ['382', '383']},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'semantic_version'},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'Version'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'coerce'},{'id': '385', 'type': 'argument_list', 'children': ['386']},{'id': '386', 'type': 'subscript', 'children': ['387', '388']},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '388', 'type': 'string', 'children': [], 'value': "'version'"},{'id': '389', 'type': 'keyword_argument', 'children': ['390', '391']},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '391', 'type': 'True', 'children': []},{'id': '392', 'type': 'pair', 'children': ['393', '394']},{'id': '393', 'type': 'string', 'children': [], 'value': "'patch_updates'"},{'id': '394', 'type': 'call', 'children': ['395', '396']},{'id': '395', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '396', 'type': 'argument_list', 'children': ['397', '398', '413']},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'patch_updates'},{'id': '398', 'type': 'keyword_argument', 'children': ['399', '400']},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '400', 'type': 'lambda', 'children': ['401', '403']},{'id': '401', 'type': 'lambda_parameters', 'children': ['402']},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '403', 'type': 'call', 'children': ['404', '409']},{'id': '404', 'type': 'attribute', 'children': ['405', '408']},{'id': '405', 'type': 'attribute', 'children': ['406', '407']},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'semantic_version'},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'Version'},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'coerce'},{'id': '409', 'type': 'argument_list', 'children': ['410']},{'id': '410', 'type': 'subscript', 'children': ['411', '412']},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '412', 'type': 'string', 'children': [], 'value': "'version'"},{'id': '413', 'type': 'keyword_argument', 'children': ['414', '415']},{'id': '414', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '415', 'type': 'True', 'children': []},{'id': '416', 'type': 'pair', 'children': ['417', '418']},{'id': '417', 'type': 'string', 'children': [], 'value': "'pre_release_updates'"},{'id': '418', 'type': 'call', 'children': ['419', '420']},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '420', 'type': 'argument_list', 'children': ['421', '422', '437']},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'pre_releases'},{'id': '422', 'type': 'keyword_argument', 'children': ['423', '424']},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '424', 'type': 'lambda', 'children': ['425', '427']},{'id': '425', 'type': 'lambda_parameters', 'children': ['426']},{'id': '426', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '427', 'type': 'call', 'children': ['428', '433']},{'id': '428', 'type': 'attribute', 'children': ['429', '432']},{'id': '429', 'type': 'attribute', 'children': ['430', '431']},{'id': '430', 'type': 'identifier', 'children': [], 'value': 'semantic_version'},{'id': '431', 'type': 'identifier', 'children': [], 'value': 'Version'},{'id': '432', 'type': 'identifier', 'children': [], 'value': 'coerce'},{'id': '433', 'type': 'argument_list', 'children': ['434']},{'id': '434', 'type': 'subscript', 'children': ['435', '436']},{'id': '435', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '436', 'type': 'string', 'children': [], 'value': "'version'"},{'id': '437', 'type': 'keyword_argument', 'children': ['438', '439']},{'id': '438', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '439', 'type': 'True', 'children': []},{'id': '440', 'type': 'pair', 'children': ['441', '442']},{'id': '441', 'type': 'string', 'children': [], 'value': "'non_semantic_versions'"},{'id': '442', 'type': 'identifier', 'children': [], 'value': 'non_semantic_versions'}
def get_package_update_list(package_name, version): package_version = semantic_version.Version.coerce(version) package_data = get_pypi_package_data(package_name) version_data = get_pypi_package_data(package_name, version) current_release = '' current_release_license = '' latest_release = '' latest_release_license = '' major_updates = [] minor_updates = [] patch_updates = [] pre_releases = [] non_semantic_versions = [] if package_data: latest_release = package_data['info']['version'] latest_release_license = package_data['info']['license'] if package_data['info']['license'] else '' for release, info in package_data['releases'].items(): parsed_release = parse(release) upload_time = None if info: upload_time = datetime.strptime(info[0]['upload_time'], "%Y-%m-%dT%H:%M:%S") try: release_version = semantic_version.Version.coerce(release) if not parsed_release.is_prerelease: if release_version in semantic_version.Spec(">=%s" % package_version.next_major()): major_updates.append({ 'version': release, 'upload_time': upload_time, }) elif release_version in semantic_version.Spec(">=%s,<%s" % (package_version.next_minor(), package_version.next_major())): minor_updates.append({ 'version': release, 'upload_time': upload_time, }) elif release_version in semantic_version.Spec(">=%s,<%s" % (package_version.next_patch(), package_version.next_minor())): patch_updates.append({ 'version': release, 'upload_time': upload_time, }) else: pre_releases.append({ 'version': release, 'upload_time': upload_time }) except ValueError: non_semantic_versions.append({'version': release, 'upload_time': upload_time}) if version_data: current_release = version_data['info']['version'] current_release_license = version_data['info']['license'] if version_data['info']['license'] else '' newer_releases = len(major_updates + minor_updates + patch_updates) return { 'current_release': current_release, 'current_release_license': current_release_license, 'latest_release': latest_release, 'latest_release_license': latest_release_license, 'newer_releases': newer_releases, 'pre_releases': len(pre_releases), 'major_updates': sorted(major_updates, key=lambda x: semantic_version.Version.coerce(x['version']), reverse=True), 'minor_updates': sorted(minor_updates, key=lambda x: semantic_version.Version.coerce(x['version']), reverse=True), 'patch_updates': sorted(patch_updates, key=lambda x: semantic_version.Version.coerce(x['version']), reverse=True), 'pre_release_updates': sorted(pre_releases, key=lambda x: semantic_version.Version.coerce(x['version']), reverse=True), 'non_semantic_versions': non_semantic_versions, }
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'page_location_template'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '16', '26', '38']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'cycle'},{'id': '9', 'type': 'attribute', 'children': ['10', '15']},{'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': 'election_day'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'cycle'},{'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': 'model_class'},{'id': '19', 'type': 'call', 'children': ['20', '25']},{'id': '20', 'type': 'attribute', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'model_type'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'model_class'},{'id': '25', 'type': 'argument_list', 'children': []},{'id': '26', 'type': 'if_statement', 'children': ['27', '30']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': '=='},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'model_class'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'ElectionDay'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'return_statement', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'string', 'children': [], 'value': '"/{}/"'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'cycle'},{'id': '38', 'type': 'if_statement', 'children': ['39', '42', '84', '182', '194']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': '=='},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'model_class'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'Office'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'if_statement', 'children': ['44', '47', '75']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'jurisdiction'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'if_statement', 'children': ['49', '58', '66']},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '55'], 'value': '=='},{'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': 'division_level'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'DivisionLevel'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'STATE'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'return_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'string', 'children': [], 'value': '"/{}/president/{{state}}"'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'cycle'},{'id': '66', 'type': 'else_clause', 'children': ['67']},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'return_statement', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'string', 'children': [], 'value': '"/{}/president/"'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'cycle'},{'id': '75', 'type': 'else_clause', 'children': ['76']},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'return_statement', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'string', 'children': [], 'value': '"/{}/{{state}}/governor/"'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'cycle'},{'id': '84', 'type': 'elif_clause', 'children': ['85', '88']},{'id': '85', 'type': 'comparison_operator', 'children': ['86', '87'], 'value': '=='},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'model_class'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'Body'},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'if_statement', 'children': ['90', '97', '139']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '96'], 'value': '=='},{'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': 'body'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'slug'},{'id': '96', 'type': 'string', 'children': [], 'value': '"senate"'},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'if_statement', 'children': ['99', '102', '130']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'jurisdiction'},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'if_statement', 'children': ['104', '113', '121']},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '110'], 'value': '=='},{'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': 'division_level'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'DivisionLevel'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'STATE'},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'return_statement', 'children': ['115']},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'string', 'children': [], 'value': '"/{}/senate/{{state}}/"'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'cycle'},{'id': '121', 'type': 'else_clause', 'children': ['122']},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'return_statement', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'string', 'children': [], 'value': '"/{}/senate/"'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'cycle'},{'id': '130', 'type': 'else_clause', 'children': ['131']},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'return_statement', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'string', 'children': [], 'value': '"/{}/{{state}}/senate/"'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'cycle'},{'id': '139', 'type': 'else_clause', 'children': ['140']},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'if_statement', 'children': ['142', '145', '173']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'jurisdiction'},{'id': '145', 'type': 'block', 'children': ['146']},{'id': '146', 'type': 'if_statement', 'children': ['147', '156', '164']},{'id': '147', 'type': 'comparison_operator', 'children': ['148', '153'], 'value': '=='},{'id': '148', 'type': 'attribute', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'division_level'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'DivisionLevel'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'STATE'},{'id': '156', 'type': 'block', 'children': ['157']},{'id': '157', 'type': 'return_statement', 'children': ['158']},{'id': '158', 'type': 'call', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'string', 'children': [], 'value': '"/{}/house/{{state}}/"'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'cycle'},{'id': '164', 'type': 'else_clause', 'children': ['165']},{'id': '165', 'type': 'block', 'children': ['166']},{'id': '166', 'type': 'return_statement', 'children': ['167']},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'string', 'children': [], 'value': '"/{}/house/"'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'cycle'},{'id': '173', 'type': 'else_clause', 'children': ['174']},{'id': '174', 'type': 'block', 'children': ['175']},{'id': '175', 'type': 'return_statement', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'string', 'children': [], 'value': '"/{}/{{state}}/house/"'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'cycle'},{'id': '182', 'type': 'elif_clause', 'children': ['183', '186']},{'id': '183', 'type': 'comparison_operator', 'children': ['184', '185'], 'value': '=='},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'model_class'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'Division'},{'id': '186', 'type': 'block', 'children': ['187']},{'id': '187', 'type': 'return_statement', 'children': ['188']},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'string', 'children': [], 'value': '"/{}/{{state}}/"'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'cycle'},{'id': '194', 'type': 'else_clause', 'children': ['195']},{'id': '195', 'type': 'block', 'children': ['196']},{'id': '196', 'type': 'return_statement', 'children': ['197']},{'id': '197', 'type': 'string', 'children': [], 'value': '"ORPHAN TYPE"'}
def page_location_template(self): cycle = self.election_day.cycle.name model_class = self.model_type.model_class() if model_class == ElectionDay: return "/{}/".format(cycle) if model_class == Office: if self.jurisdiction: if self.division_level.name == DivisionLevel.STATE: return "/{}/president/{{state}}".format(cycle) else: return "/{}/president/".format(cycle) else: return "/{}/{{state}}/governor/".format(cycle) elif model_class == Body: if self.body.slug == "senate": if self.jurisdiction: if self.division_level.name == DivisionLevel.STATE: return "/{}/senate/{{state}}/".format(cycle) else: return "/{}/senate/".format(cycle) else: return "/{}/{{state}}/senate/".format(cycle) else: if self.jurisdiction: if self.division_level.name == DivisionLevel.STATE: return "/{}/house/{{state}}/".format(cycle) else: return "/{}/house/".format(cycle) else: return "/{}/{{state}}/house/".format(cycle) elif model_class == Division: return "/{}/{{state}}/".format(cycle) else: return "ORPHAN TYPE"
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_ask'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'answers'},{'id': '6', 'type': 'block', 'children': ['7', '38']},{'id': '7', 'type': 'if_statement', 'children': ['8', '15', '28']},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '10', 'type': 'argument_list', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'for_statement', 'children': ['17', '18', '21']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'answers'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'answers'},{'id': '28', 'type': 'else_clause', 'children': ['29']},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '37']},{'id': '32', 'type': 'attribute', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'answers'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'answers'},{'id': '38', 'type': 'while_statement', 'children': ['39', '41']},{'id': '39', 'type': '()', 'children': ['40']},{'id': '40', 'type': 'True', 'children': []},{'id': '41', 'type': 'block', 'children': ['42', '50', '69', '128', '139']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '45', 'type': 'binary_operator', 'children': ['46', '49'], 'value': '%'},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'question'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'answers'},{'id': '50', 'type': 'if_statement', 'children': ['51', '57']},{'id': '51', 'type': 'not_operator', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '56', 'type': 'argument_list', 'children': []},{'id': '57', 'type': 'block', 'children': ['58', '67']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'binary_operator', 'children': ['65', '66'], 'value': '%'},{'id': '65', 'type': 'string', 'children': [], 'value': '\'No choices were supplied for "%s"\''},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '67', 'type': 'return_statement', 'children': ['68']},{'id': '68', 'type': 'None', 'children': []},{'id': '69', 'type': 'if_statement', 'children': ['70', '75', '115']},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '74'], 'value': 'in'},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'answers'},{'id': '75', 'type': 'block', 'children': ['76', '89', '102']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'Validator'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'stringify'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'answers'},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'answer'},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '95', 'type': 'identifier', 'children': [], 'value': '_get_input'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'binary_operator', 'children': ['98', '99'], 'value': '%'},{'id': '98', 'type': 'string', 'children': [], 'value': '"%s [%s]: "'},{'id': '99', 'type': 'tuple', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '102', 'type': 'if_statement', 'children': ['103', '106']},{'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': '=='},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'answer'},{'id': '105', 'type': 'string', 'children': [], 'value': "''"},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'answer'},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'answers'},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '115', 'type': 'else_clause', 'children': ['116']},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'answer'},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '123', 'type': 'identifier', 'children': [], 'value': '_get_input'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'binary_operator', 'children': ['126', '127'], 'value': '%'},{'id': '126', 'type': 'string', 'children': [], 'value': '"%s: "'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '128', 'type': 'if_statement', 'children': ['129', '136']},{'id': '129', 'type': 'boolean_operator', 'children': ['130', '133'], 'value': 'and'},{'id': '130', 'type': 'comparison_operator', 'children': ['131', '132'], 'value': '=='},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'answer'},{'id': '132', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'multiple'},{'id': '136', 'type': 'block', 'children': ['137']},{'id': '137', 'type': 'return_statement', 'children': ['138']},{'id': '138', 'type': 'None', 'children': []},{'id': '139', 'type': 'if_statement', 'children': ['140', '146', '153']},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'validate'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'answer'},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'return_statement', 'children': ['148']},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'answer'},{'id': '152', 'type': 'argument_list', 'children': []},{'id': '153', 'type': 'else_clause', 'children': ['154']},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'if_statement', 'children': ['156', '163', '188']},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '158', 'type': 'argument_list', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'for_statement', 'children': ['165', '166', '169']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'if_statement', 'children': ['171', '178']},{'id': '171', 'type': 'comparison_operator', 'children': ['172', '177'], 'value': '!='},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '176', 'type': 'argument_list', 'children': []},{'id': '177', 'type': 'string', 'children': [], 'value': "''"},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '187', 'type': 'argument_list', 'children': []},{'id': '188', 'type': 'else_clause', 'children': ['189']},{'id': '189', 'type': 'block', 'children': ['190']},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'call', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'call', 'children': ['195', '200']},{'id': '195', 'type': 'attribute', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '200', 'type': 'argument_list', 'children': []}
def _ask(self, answers): if isinstance(self.validator, list): for v in self.validator: v.answers = answers else: self.validator.answers = answers while(True): q = self.question % answers if not self.choices(): logger.warn('No choices were supplied for "%s"' % q) return None if self.value in answers: default = Validator.stringify(answers[self.value]) answer = self._get_input("%s [%s]: " % (q, default)) if answer == '': answer = answers[self.value] else: answer = self._get_input("%s: " % q) if answer == '.' and self.multiple: return None if self.validate(answer): return self.answer() else: if isinstance(self.validator, list): for v in self.validator: if v.error() != '': print(v.error()) else: print(self.validator.error())
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_annotate_fn_args'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'fn_opname'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'nargs'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'nkw'},{'id': '9', 'type': 'unary_operator', 'children': ['10'], 'value': '-'},{'id': '10', 'type': 'integer', 'children': [], 'value': '1'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'consume_fn_name'},{'id': '13', 'type': 'True', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '19', '148', '342', '456']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'kwarg_names'},{'id': '18', 'type': 'list', 'children': [], 'value': '[]'},{'id': '19', 'type': 'if_statement', 'children': ['20', '24']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': '=='},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'nkw'},{'id': '22', 'type': 'unary_operator', 'children': ['23'], 'value': '-'},{'id': '23', 'type': 'integer', 'children': [], 'value': '1'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'if_statement', 'children': ['26', '33', '48']},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '32'], 'value': '<'},{'id': '27', 'type': 'subscript', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'version_info'},{'id': '31', 'type': 'integer', 'children': [], 'value': '0'},{'id': '32', 'type': 'integer', 'children': [], 'value': '3'},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '39']},{'id': '36', 'type': 'pattern_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'nargs'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'nkw'},{'id': '39', 'type': 'tuple', 'children': ['40', '43']},{'id': '40', 'type': 'binary_operator', 'children': ['41', '42'], 'value': '%'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'nargs'},{'id': '42', 'type': 'integer', 'children': [], 'value': '256'},{'id': '43', 'type': 'binary_operator', 'children': ['44', '47'], 'value': '//'},{'id': '44', 'type': 'binary_operator', 'children': ['45', '46'], 'value': '*'},{'id': '45', 'type': 'integer', 'children': [], 'value': '2'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'nargs'},{'id': '47', 'type': 'integer', 'children': [], 'value': '256'},{'id': '48', 'type': 'else_clause', 'children': ['49']},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'if_statement', 'children': ['51', '54', '142']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': '=='},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'fn_opname'},{'id': '53', 'type': 'string', 'children': [], 'value': "'CALL_FUNCTION_KW'"},{'id': '54', 'type': 'block', 'children': ['55', '74', '91', '99', '111', '118', '125', '129']},{'id': '55', 'type': 'if_statement', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'qj'},{'id': '58', 'type': 'identifier', 'children': [], 'value': '_DEBUG_QJ'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'assert_statement', 'children': ['61']},{'id': '61', 'type': 'boolean_operator', 'children': ['62', '66'], 'value': 'and'},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '73'], 'value': '=='},{'id': '67', 'type': 'attribute', 'children': ['68', '72']},{'id': '68', 'type': 'subscript', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '70', 'type': 'unary_operator', 'children': ['71'], 'value': '-'},{'id': '71', 'type': 'integer', 'children': [], 'value': '1'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'opname'},{'id': '73', 'type': 'string', 'children': [], 'value': "'LOAD_CONST'"},{'id': '74', 'type': 'if_statement', 'children': ['75', '89']},{'id': '75', 'type': 'boolean_operator', 'children': ['76', '81'], 'value': 'or'},{'id': '76', 'type': 'not_operator', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '88'], 'value': '!='},{'id': '82', 'type': 'attribute', 'children': ['83', '87']},{'id': '83', 'type': 'subscript', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '85', 'type': 'unary_operator', 'children': ['86'], 'value': '-'},{'id': '86', 'type': 'integer', 'children': [], 'value': '1'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'opname'},{'id': '88', 'type': 'string', 'children': [], 'value': "'LOAD_CONST'"},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'return_statement', 'children': []},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'se'},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '98', 'type': 'argument_list', 'children': []},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'kwarg_names'},{'id': '102', 'type': 'subscript', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'se'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'oparg_repr'},{'id': '106', 'type': 'slice', 'children': ['107', '108', '109']},{'id': '107', 'type': 'colon', 'children': []},{'id': '108', 'type': 'colon', 'children': []},{'id': '109', 'type': 'unary_operator', 'children': ['110'], 'value': '-'},{'id': '110', 'type': 'integer', 'children': [], 'value': '1'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'se'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'oparg_repr'},{'id': '116', 'type': 'list', 'children': ['117'], 'value': "['']"},{'id': '117', 'type': 'string', 'children': [], 'value': "''"},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'nkw'},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'kwarg_names'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'augmented_assignment', 'children': ['127', '128'], 'value': '-='},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'nargs'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'nkw'},{'id': '129', 'type': 'if_statement', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'qj'},{'id': '132', 'type': 'identifier', 'children': [], 'value': '_DEBUG_QJ'},{'id': '133', 'type': 'block', 'children': ['134']},{'id': '134', 'type': 'assert_statement', 'children': ['135']},{'id': '135', 'type': 'boolean_operator', 'children': ['136', '139'], 'value': 'and'},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '138'], 'value': '>='},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'nargs'},{'id': '138', 'type': 'integer', 'children': [], 'value': '0'},{'id': '139', 'type': 'comparison_operator', 'children': ['140', '141'], 'value': '>'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'nkw'},{'id': '141', 'type': 'integer', 'children': [], 'value': '0'},{'id': '142', 'type': 'else_clause', 'children': ['143']},{'id': '143', 'type': 'block', 'children': ['144']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'nkw'},{'id': '147', 'type': 'integer', 'children': [], 'value': '0'},{'id': '148', 'type': 'for_statement', 'children': ['149', '150', '154']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'nkw'},{'id': '154', 'type': 'block', 'children': ['155', '163', '189']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'se'},{'id': '158', 'type': 'call', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '162', 'type': 'argument_list', 'children': []},{'id': '163', 'type': 'if_statement', 'children': ['164', '187']},{'id': '164', 'type': 'boolean_operator', 'children': ['165', '170'], 'value': 'and'},{'id': '165', 'type': 'comparison_operator', 'children': ['166', '169'], 'value': '=='},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'se'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'stack_depth'},{'id': '169', 'type': 'integer', 'children': [], 'value': '0'},{'id': '170', 'type': '()', 'children': ['171']},{'id': '171', 'type': 'boolean_operator', 'children': ['172', '180'], 'value': 'or'},{'id': '172', 'type': 'comparison_operator', 'children': ['173', '179'], 'value': '=='},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'se'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'oparg_repr'},{'id': '179', 'type': 'integer', 'children': [], 'value': '0'},{'id': '180', 'type': 'comparison_operator', 'children': ['181', '186'], 'value': '=='},{'id': '181', 'type': 'subscript', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'se'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'oparg_repr'},{'id': '185', 'type': 'integer', 'children': [], 'value': '0'},{'id': '186', 'type': 'string', 'children': [], 'value': "''"},{'id': '187', 'type': 'block', 'children': ['188']},{'id': '188', 'type': 'continue_statement', 'children': []},{'id': '189', 'type': 'if_statement', 'children': ['190', '203', '229']},{'id': '190', 'type': 'boolean_operator', 'children': ['191', '196'], 'value': 'and'},{'id': '191', 'type': 'comparison_operator', 'children': ['192', '195'], 'value': '=='},{'id': '192', 'type': 'binary_operator', 'children': ['193', '194'], 'value': '%'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '194', 'type': 'integer', 'children': [], 'value': '2'},{'id': '195', 'type': 'integer', 'children': [], 'value': '1'},{'id': '196', 'type': 'comparison_operator', 'children': ['197', '202'], 'value': '<'},{'id': '197', 'type': 'subscript', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'version_info'},{'id': '201', 'type': 'integer', 'children': [], 'value': '0'},{'id': '202', 'type': 'integer', 'children': [], 'value': '3'},{'id': '203', 'type': 'block', 'children': ['204', '215']},{'id': '204', 'type': 'if_statement', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'qj'},{'id': '207', 'type': 'identifier', 'children': [], 'value': '_DEBUG_QJ'},{'id': '208', 'type': 'block', 'children': ['209']},{'id': '209', 'type': 'assert_statement', 'children': ['210']},{'id': '210', 'type': 'comparison_operator', 'children': ['211', '214'], 'value': '=='},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'se'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'opname'},{'id': '214', 'type': 'string', 'children': [], 'value': "'LOAD_CONST'"},{'id': '215', 'type': 'if_statement', 'children': ['216', '221']},{'id': '216', 'type': 'comparison_operator', 'children': ['217', '220'], 'value': '=='},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'se'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'opname'},{'id': '220', 'type': 'string', 'children': [], 'value': "'LOAD_CONST'"},{'id': '221', 'type': 'block', 'children': ['222']},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'augmented_assignment', 'children': ['224', '227'], 'value': '+='},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'se'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'oparg_repr'},{'id': '227', 'type': 'list', 'children': ['228'], 'value': "['=']"},{'id': '228', 'type': 'string', 'children': [], 'value': "'='"},{'id': '229', 'type': 'else_clause', 'children': ['230']},{'id': '230', 'type': 'block', 'children': ['231', '235', '262', '286', '306']},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'pops'},{'id': '234', 'type': 'list', 'children': [], 'value': '[]'},{'id': '235', 'type': 'if_statement', 'children': ['236', '244']},{'id': '236', 'type': 'call', 'children': ['237', '242']},{'id': '237', 'type': 'attribute', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'se'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'opname'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'string', 'children': [], 'value': "'CALL_FUNCTION'"},{'id': '244', 'type': 'block', 'children': ['245']},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'call', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': '_annotate_fn_args'},{'id': '248', 'type': 'argument_list', 'children': ['249', '253', '256', '259', '261']},{'id': '249', 'type': 'subscript', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '251', 'type': 'slice', 'children': ['252']},{'id': '252', 'type': 'colon', 'children': []},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'se'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'opname'},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'se'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'oparg'},{'id': '259', 'type': 'unary_operator', 'children': ['260'], 'value': '-'},{'id': '260', 'type': 'integer', 'children': [], 'value': '1'},{'id': '261', 'type': 'True', 'children': []},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'assignment', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'pops'},{'id': '265', 'type': 'call', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': '_collect_pops'},{'id': '267', 'type': 'argument_list', 'children': ['268', '269', '284', '285']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '269', 'type': 'conditional_expression', 'children': ['270', '275', '283'], 'value': 'if'},{'id': '270', 'type': 'binary_operator', 'children': ['271', '274'], 'value': '-'},{'id': '271', 'type': 'attribute', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'se'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'stack_depth'},{'id': '274', 'type': 'integer', 'children': [], 'value': '1'},{'id': '275', 'type': 'call', 'children': ['276', '281']},{'id': '276', 'type': 'attribute', 'children': ['277', '280']},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'se'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'opname'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '281', 'type': 'argument_list', 'children': ['282']},{'id': '282', 'type': 'string', 'children': [], 'value': "'CALL_FUNCTION'"},{'id': '283', 'type': 'integer', 'children': [], 'value': '0'},{'id': '284', 'type': 'list', 'children': [], 'value': '[]'},{'id': '285', 'type': 'False', 'children': []},{'id': '286', 'type': 'if_statement', 'children': ['287', '295']},{'id': '287', 'type': 'boolean_operator', 'children': ['288', '291'], 'value': 'and'},{'id': '288', 'type': 'comparison_operator', 'children': ['289', '290'], 'value': '>'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '290', 'type': 'integer', 'children': [], 'value': '1'},{'id': '291', 'type': 'call', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '293', 'type': 'argument_list', 'children': ['294']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'pops'},{'id': '295', 'type': 'block', 'children': ['296']},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'augmented_assignment', 'children': ['298', '304'], 'value': '+='},{'id': '298', 'type': 'attribute', 'children': ['299', '303']},{'id': '299', 'type': 'subscript', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'pops'},{'id': '301', 'type': 'unary_operator', 'children': ['302'], 'value': '-'},{'id': '302', 'type': 'integer', 'children': [], 'value': '1'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'oparg_repr'},{'id': '304', 'type': 'list', 'children': ['305'], 'value': "[',']"},{'id': '305', 'type': 'string', 'children': [], 'value': "','"},{'id': '306', 'type': 'if_statement', 'children': ['307', '314']},{'id': '307', 'type': 'comparison_operator', 'children': ['308', '313'], 'value': '>='},{'id': '308', 'type': 'subscript', 'children': ['309', '312']},{'id': '309', 'type': 'attribute', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'version_info'},{'id': '312', 'type': 'integer', 'children': [], 'value': '0'},{'id': '313', 'type': 'integer', 'children': [], 'value': '3'},{'id': '314', 'type': 'block', 'children': ['315', '328']},{'id': '315', 'type': 'expression_statement', 'children': ['316']},{'id': '316', 'type': 'assignment', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'target_se'},{'id': '318', 'type': 'conditional_expression', 'children': ['319', '323', '327'], 'value': 'if'},{'id': '319', 'type': 'subscript', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'pops'},{'id': '321', 'type': 'unary_operator', 'children': ['322'], 'value': '-'},{'id': '322', 'type': 'integer', 'children': [], 'value': '1'},{'id': '323', 'type': 'call', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '325', 'type': 'argument_list', 'children': ['326']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'pops'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'se'},{'id': '328', 'type': 'expression_statement', 'children': ['329']},{'id': '329', 'type': 'assignment', 'children': ['330', '333']},{'id': '330', 'type': 'attribute', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'target_se'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'oparg_repr'},{'id': '333', 'type': 'binary_operator', 'children': ['334', '339'], 'value': '+'},{'id': '334', 'type': 'list', 'children': ['335', '338'], 'value': "[kwarg_names[i], '=']"},{'id': '335', 'type': 'subscript', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'kwarg_names'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '338', 'type': 'string', 'children': [], 'value': "'='"},{'id': '339', 'type': 'attribute', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'target_se'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'oparg_repr'},{'id': '342', 'type': 'for_statement', 'children': ['343', '344', '348']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '344', 'type': 'call', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '346', 'type': 'argument_list', 'children': ['347']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'nargs'},{'id': '348', 'type': 'block', 'children': ['349', '357']},{'id': '349', 'type': 'expression_statement', 'children': ['350']},{'id': '350', 'type': 'assignment', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'se'},{'id': '352', 'type': 'call', 'children': ['353', '356']},{'id': '353', 'type': 'attribute', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '356', 'type': 'argument_list', 'children': []},{'id': '357', 'type': 'if_statement', 'children': ['358', '366', '381', '417']},{'id': '358', 'type': 'call', 'children': ['359', '364']},{'id': '359', 'type': 'attribute', 'children': ['360', '363']},{'id': '360', 'type': 'attribute', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'se'},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'opname'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '364', 'type': 'argument_list', 'children': ['365']},{'id': '365', 'type': 'string', 'children': [], 'value': "'CALL_FUNCTION'"},{'id': '366', 'type': 'block', 'children': ['367']},{'id': '367', 'type': 'expression_statement', 'children': ['368']},{'id': '368', 'type': 'call', 'children': ['369', '370']},{'id': '369', 'type': 'identifier', 'children': [], 'value': '_annotate_fn_args'},{'id': '370', 'type': 'argument_list', 'children': ['371', '372', '375', '378', '380']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '372', 'type': 'attribute', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'se'},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'opname'},{'id': '375', 'type': 'attribute', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'se'},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'oparg'},{'id': '378', 'type': 'unary_operator', 'children': ['379'], 'value': '-'},{'id': '379', 'type': 'integer', 'children': [], 'value': '1'},{'id': '380', 'type': 'True', 'children': []},{'id': '381', 'type': 'elif_clause', 'children': ['382', '399']},{'id': '382', 'type': 'boolean_operator', 'children': ['383', '389'], 'value': 'and'},{'id': '383', 'type': 'call', 'children': ['384', '385']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '385', 'type': 'argument_list', 'children': ['386']},{'id': '386', 'type': 'attribute', 'children': ['387', '388']},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'se'},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'oparg_repr'},{'id': '389', 'type': 'comparison_operator', 'children': ['390', '395'], 'value': 'in'},{'id': '390', 'type': 'subscript', 'children': ['391', '394']},{'id': '391', 'type': 'attribute', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'se'},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'oparg_repr'},{'id': '394', 'type': 'integer', 'children': [], 'value': '0'},{'id': '395', 'type': 'set', 'children': ['396', '397', '398']},{'id': '396', 'type': 'string', 'children': [], 'value': "']'"},{'id': '397', 'type': 'string', 'children': [], 'value': "'}'"},{'id': '398', 'type': 'string', 'children': [], 'value': "')'"},{'id': '399', 'type': 'block', 'children': ['400']},{'id': '400', 'type': 'if_statement', 'children': ['401', '409']},{'id': '401', 'type': '()', 'children': ['402']},{'id': '402', 'type': 'boolean_operator', 'children': ['403', '406'], 'value': 'or'},{'id': '403', 'type': 'comparison_operator', 'children': ['404', '405'], 'value': '>'},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '405', 'type': 'integer', 'children': [], 'value': '0'},{'id': '406', 'type': 'comparison_operator', 'children': ['407', '408'], 'value': '>'},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'nkw'},{'id': '408', 'type': 'integer', 'children': [], 'value': '0'},{'id': '409', 'type': 'block', 'children': ['410']},{'id': '410', 'type': 'expression_statement', 'children': ['411']},{'id': '411', 'type': 'augmented_assignment', 'children': ['412', '415'], 'value': '+='},{'id': '412', 'type': 'attribute', 'children': ['413', '414']},{'id': '413', 'type': 'identifier', 'children': [], 'value': 'se'},{'id': '414', 'type': 'identifier', 'children': [], 'value': 'oparg_repr'},{'id': '415', 'type': 'list', 'children': ['416'], 'value': "[',']"},{'id': '416', 'type': 'string', 'children': [], 'value': "','"},{'id': '417', 'type': 'else_clause', 'children': ['418']},{'id': '418', 'type': 'block', 'children': ['419', '431']},{'id': '419', 'type': 'expression_statement', 'children': ['420']},{'id': '420', 'type': 'assignment', 'children': ['421', '422']},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'pops'},{'id': '422', 'type': 'call', 'children': ['423', '424']},{'id': '423', 'type': 'identifier', 'children': [], 'value': '_collect_pops'},{'id': '424', 'type': 'argument_list', 'children': ['425', '426', '429', '430']},{'id': '425', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '426', 'type': 'attribute', 'children': ['427', '428']},{'id': '427', 'type': 'identifier', 'children': [], 'value': 'se'},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'stack_depth'},{'id': '429', 'type': 'list', 'children': [], 'value': '[]'},{'id': '430', 'type': 'False', 'children': []},{'id': '431', 'type': 'if_statement', 'children': ['432', '445']},{'id': '432', 'type': 'boolean_operator', 'children': ['433', '441'], 'value': 'and'},{'id': '433', 'type': '()', 'children': ['434']},{'id': '434', 'type': 'boolean_operator', 'children': ['435', '438'], 'value': 'or'},{'id': '435', 'type': 'comparison_operator', 'children': ['436', '437'], 'value': '>'},{'id': '436', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '437', 'type': 'integer', 'children': [], 'value': '0'},{'id': '438', 'type': 'comparison_operator', 'children': ['439', '440'], 'value': '>'},{'id': '439', 'type': 'identifier', 'children': [], 'value': 'nkw'},{'id': '440', 'type': 'integer', 'children': [], 'value': '0'},{'id': '441', 'type': 'call', 'children': ['442', '443']},{'id': '442', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '443', 'type': 'argument_list', 'children': ['444']},{'id': '444', 'type': 'identifier', 'children': [], 'value': 'pops'},{'id': '445', 'type': 'block', 'children': ['446']},{'id': '446', 'type': 'expression_statement', 'children': ['447']},{'id': '447', 'type': 'augmented_assignment', 'children': ['448', '454'], 'value': '+='},{'id': '448', 'type': 'attribute', 'children': ['449', '453']},{'id': '449', 'type': 'subscript', 'children': ['450', '451']},{'id': '450', 'type': 'identifier', 'children': [], 'value': 'pops'},{'id': '451', 'type': 'unary_operator', 'children': ['452'], 'value': '-'},{'id': '452', 'type': 'integer', 'children': [], 'value': '1'},{'id': '453', 'type': 'identifier', 'children': [], 'value': 'oparg_repr'},{'id': '454', 'type': 'list', 'children': ['455'], 'value': "[',']"},{'id': '455', 'type': 'string', 'children': [], 'value': "','"},{'id': '456', 'type': 'if_statement', 'children': ['457', '458']},{'id': '457', 'type': 'identifier', 'children': [], 'value': 'consume_fn_name'},{'id': '458', 'type': 'block', 'children': ['459']},{'id': '459', 'type': 'expression_statement', 'children': ['460']},{'id': '460', 'type': 'call', 'children': ['461', '462']},{'id': '461', 'type': 'identifier', 'children': [], 'value': '_collect_pops'},{'id': '462', 'type': 'argument_list', 'children': ['463', '464', '466', '467']},{'id': '463', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '464', 'type': 'unary_operator', 'children': ['465'], 'value': '-'},{'id': '465', 'type': 'integer', 'children': [], 'value': '1'},{'id': '466', 'type': 'list', 'children': [], 'value': '[]'},{'id': '467', 'type': 'False', 'children': []}
def _annotate_fn_args(stack, fn_opname, nargs, nkw=-1, consume_fn_name=True): kwarg_names = [] if nkw == -1: if sys.version_info[0] < 3: nargs, nkw = (nargs % 256, 2 * nargs // 256) else: if fn_opname == 'CALL_FUNCTION_KW': if qj._DEBUG_QJ: assert len(stack) and stack[-1].opname == 'LOAD_CONST' if not len(stack) or stack[-1].opname != 'LOAD_CONST': return se = stack.pop() kwarg_names = se.oparg_repr[::-1] se.oparg_repr = [''] nkw = len(kwarg_names) nargs -= nkw if qj._DEBUG_QJ: assert nargs >= 0 and nkw > 0 else: nkw = 0 for i in range(nkw): se = stack.pop() if se.stack_depth == 0 and (len(se.oparg_repr) == 0 or se.oparg_repr[0] == ''): continue if i % 2 == 1 and sys.version_info[0] < 3: if qj._DEBUG_QJ: assert se.opname == 'LOAD_CONST' if se.opname == 'LOAD_CONST': se.oparg_repr += ['='] else: pops = [] if se.opname.startswith('CALL_FUNCTION'): _annotate_fn_args(stack[:], se.opname, se.oparg, -1, True) pops = _collect_pops(stack, se.stack_depth - 1 if se.opname.startswith('CALL_FUNCTION') else 0, [], False) if i > 1 and len(pops): pops[-1].oparg_repr += [','] if sys.version_info[0] >= 3: target_se = pops[-1] if len(pops) else se target_se.oparg_repr = [kwarg_names[i], '='] + target_se.oparg_repr for i in range(nargs): se = stack.pop() if se.opname.startswith('CALL_FUNCTION'): _annotate_fn_args(stack, se.opname, se.oparg, -1, True) elif len(se.oparg_repr) and se.oparg_repr[0] in {']', '}', ')'}: if (i > 0 or nkw > 0): se.oparg_repr += [','] else: pops = _collect_pops(stack, se.stack_depth, [], False) if (i > 0 or nkw > 0) and len(pops): pops[-1].oparg_repr += [','] if consume_fn_name: _collect_pops(stack, -1, [], False)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'generate_mediation_matrix'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'dsm'},{'id': '5', 'type': 'block', 'children': ['6', '12', '18', '26', '37', '52', '70', '385']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'dsm'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ent'},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'dsm'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'entities'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '21', 'type': 'subscript', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'dsm'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '25', 'type': 'integer', 'children': [], 'value': '0'},{'id': '26', 'type': 'if_statement', 'children': ['27', '29']},{'id': '27', 'type': 'not_operator', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'cat'},{'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': 'cat'},{'id': '33', 'type': 'binary_operator', 'children': ['34', '36'], 'value': '*'},{'id': '34', 'type': 'list', 'children': ['35'], 'value': "['appmodule']"},{'id': '35', 'type': 'string', 'children': [], 'value': "'appmodule'"},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'packages'},{'id': '40', 'type': 'list_comprehension', 'children': ['41', '49']},{'id': '41', 'type': 'subscript', 'children': ['42', '48']},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '48', 'type': 'integer', 'children': [], 'value': '0'},{'id': '49', 'type': 'for_in_clause', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'ent'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'mediation_matrix'},{'id': '55', 'type': 'list_comprehension', 'children': ['56', '64']},{'id': '56', 'type': 'list_comprehension', 'children': ['57', '58']},{'id': '57', 'type': 'integer', 'children': [], 'value': '0'},{'id': '58', 'type': 'for_in_clause', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '64', 'type': 'for_in_clause', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '70', 'type': 'for_statement', 'children': ['71', '72', '77']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76']},{'id': '75', 'type': 'integer', 'children': [], 'value': '0'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'for_statement', 'children': ['79', '80', '85']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '82', 'type': 'argument_list', 'children': ['83', '84']},{'id': '83', 'type': 'integer', 'children': [], 'value': '0'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'if_statement', 'children': ['87', '92', '119', '172', '226', '282', '336', '374']},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '91'], 'value': '=='},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '91', 'type': 'string', 'children': [], 'value': "'framework'"},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'if_statement', 'children': ['94', '99', '109']},{'id': '94', 'type': 'comparison_operator', 'children': ['95', '98'], 'value': '=='},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '98', 'type': 'string', 'children': [], 'value': "'framework'"},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '107']},{'id': '102', 'type': 'subscript', 'children': ['103', '106']},{'id': '103', 'type': 'subscript', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'mediation_matrix'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '107', 'type': 'unary_operator', 'children': ['108'], 'value': '-'},{'id': '108', 'type': 'integer', 'children': [], 'value': '1'},{'id': '109', 'type': 'else_clause', 'children': ['110']},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '118']},{'id': '113', 'type': 'subscript', 'children': ['114', '117']},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'mediation_matrix'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '118', 'type': 'integer', 'children': [], 'value': '0'},{'id': '119', 'type': 'elif_clause', 'children': ['120', '125']},{'id': '120', 'type': 'comparison_operator', 'children': ['121', '124'], 'value': '=='},{'id': '121', 'type': 'subscript', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '124', 'type': 'string', 'children': [], 'value': "'corelib'"},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'if_statement', 'children': ['127', '152', '162']},{'id': '127', 'type': '()', 'children': ['128']},{'id': '128', 'type': 'boolean_operator', 'children': ['129', '149'], 'value': 'or'},{'id': '129', 'type': 'boolean_operator', 'children': ['130', '137'], 'value': 'or'},{'id': '130', 'type': 'comparison_operator', 'children': ['131', '134'], 'value': 'in'},{'id': '131', 'type': 'subscript', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '134', 'type': 'tuple', 'children': ['135', '136']},{'id': '135', 'type': 'string', 'children': [], 'value': "'framework'"},{'id': '136', 'type': 'string', 'children': [], 'value': "'corelib'"},{'id': '137', 'type': 'call', 'children': ['138', '143']},{'id': '138', 'type': 'attribute', 'children': ['139', '142']},{'id': '139', 'type': 'subscript', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'ent'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'binary_operator', 'children': ['145', '148'], 'value': '+'},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'packages'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '148', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '149', 'type': 'comparison_operator', 'children': ['150', '151'], 'value': '=='},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '160']},{'id': '155', 'type': 'subscript', 'children': ['156', '159']},{'id': '156', 'type': 'subscript', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'mediation_matrix'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '160', 'type': 'unary_operator', 'children': ['161'], 'value': '-'},{'id': '161', 'type': 'integer', 'children': [], 'value': '1'},{'id': '162', 'type': 'else_clause', 'children': ['163']},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '171']},{'id': '166', 'type': 'subscript', 'children': ['167', '170']},{'id': '167', 'type': 'subscript', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'mediation_matrix'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '171', 'type': 'integer', 'children': [], 'value': '0'},{'id': '172', 'type': 'elif_clause', 'children': ['173', '178']},{'id': '173', 'type': 'comparison_operator', 'children': ['174', '177'], 'value': '=='},{'id': '174', 'type': 'subscript', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '177', 'type': 'string', 'children': [], 'value': "'applib'"},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'if_statement', 'children': ['180', '206', '216']},{'id': '180', 'type': '()', 'children': ['181']},{'id': '181', 'type': 'boolean_operator', 'children': ['182', '203'], 'value': 'or'},{'id': '182', 'type': 'boolean_operator', 'children': ['183', '191'], 'value': 'or'},{'id': '183', 'type': 'comparison_operator', 'children': ['184', '187'], 'value': 'in'},{'id': '184', 'type': 'subscript', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '187', 'type': 'tuple', 'children': ['188', '189', '190']},{'id': '188', 'type': 'string', 'children': [], 'value': "'framework'"},{'id': '189', 'type': 'string', 'children': [], 'value': "'corelib'"},{'id': '190', 'type': 'string', 'children': [], 'value': "'applib'"},{'id': '191', 'type': 'call', 'children': ['192', '197']},{'id': '192', 'type': 'attribute', 'children': ['193', '196']},{'id': '193', 'type': 'subscript', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'ent'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'binary_operator', 'children': ['199', '202'], 'value': '+'},{'id': '199', 'type': 'subscript', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'packages'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '202', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '203', 'type': 'comparison_operator', 'children': ['204', '205'], 'value': '=='},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '206', 'type': 'block', 'children': ['207']},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '214']},{'id': '209', 'type': 'subscript', 'children': ['210', '213']},{'id': '210', 'type': 'subscript', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'mediation_matrix'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '214', 'type': 'unary_operator', 'children': ['215'], 'value': '-'},{'id': '215', 'type': 'integer', 'children': [], 'value': '1'},{'id': '216', 'type': 'else_clause', 'children': ['217']},{'id': '217', 'type': 'block', 'children': ['218']},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'assignment', 'children': ['220', '225']},{'id': '220', 'type': 'subscript', 'children': ['221', '224']},{'id': '221', 'type': 'subscript', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'mediation_matrix'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '225', 'type': 'integer', 'children': [], 'value': '0'},{'id': '226', 'type': 'elif_clause', 'children': ['227', '232']},{'id': '227', 'type': 'comparison_operator', 'children': ['228', '231'], 'value': '=='},{'id': '228', 'type': 'subscript', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '231', 'type': 'string', 'children': [], 'value': "'appmodule'"},{'id': '232', 'type': 'block', 'children': ['233']},{'id': '233', 'type': 'if_statement', 'children': ['234', '262', '272']},{'id': '234', 'type': '()', 'children': ['235']},{'id': '235', 'type': 'boolean_operator', 'children': ['236', '259'], 'value': 'or'},{'id': '236', 'type': 'boolean_operator', 'children': ['237', '247'], 'value': 'or'},{'id': '237', 'type': 'comparison_operator', 'children': ['238', '241'], 'value': 'in'},{'id': '238', 'type': 'subscript', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '241', 'type': 'tuple', 'children': ['242', '243', '244', '245', '246']},{'id': '242', 'type': 'string', 'children': [], 'value': "'framework'"},{'id': '243', 'type': 'string', 'children': [], 'value': "'corelib'"},{'id': '244', 'type': 'string', 'children': [], 'value': "'applib'"},{'id': '245', 'type': 'string', 'children': [], 'value': "'broker'"},{'id': '246', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '247', 'type': 'call', 'children': ['248', '253']},{'id': '248', 'type': 'attribute', 'children': ['249', '252']},{'id': '249', 'type': 'subscript', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'ent'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'binary_operator', 'children': ['255', '258'], 'value': '+'},{'id': '255', 'type': 'subscript', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'packages'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '258', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '259', 'type': 'comparison_operator', 'children': ['260', '261'], 'value': '=='},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '262', 'type': 'block', 'children': ['263']},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'assignment', 'children': ['265', '270']},{'id': '265', 'type': 'subscript', 'children': ['266', '269']},{'id': '266', 'type': 'subscript', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'mediation_matrix'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '270', 'type': 'unary_operator', 'children': ['271'], 'value': '-'},{'id': '271', 'type': 'integer', 'children': [], 'value': '1'},{'id': '272', 'type': 'else_clause', 'children': ['273']},{'id': '273', 'type': 'block', 'children': ['274']},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'assignment', 'children': ['276', '281']},{'id': '276', 'type': 'subscript', 'children': ['277', '280']},{'id': '277', 'type': 'subscript', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'mediation_matrix'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '281', 'type': 'integer', 'children': [], 'value': '0'},{'id': '282', 'type': 'elif_clause', 'children': ['283', '288']},{'id': '283', 'type': 'comparison_operator', 'children': ['284', '287'], 'value': '=='},{'id': '284', 'type': 'subscript', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '287', 'type': 'string', 'children': [], 'value': "'broker'"},{'id': '288', 'type': 'block', 'children': ['289']},{'id': '289', 'type': 'if_statement', 'children': ['290', '316', '326']},{'id': '290', 'type': '()', 'children': ['291']},{'id': '291', 'type': 'boolean_operator', 'children': ['292', '313'], 'value': 'or'},{'id': '292', 'type': 'boolean_operator', 'children': ['293', '301'], 'value': 'or'},{'id': '293', 'type': 'comparison_operator', 'children': ['294', '297'], 'value': 'in'},{'id': '294', 'type': 'subscript', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '297', 'type': 'tuple', 'children': ['298', '299', '300']},{'id': '298', 'type': 'string', 'children': [], 'value': "'appmodule'"},{'id': '299', 'type': 'string', 'children': [], 'value': "'corelib'"},{'id': '300', 'type': 'string', 'children': [], 'value': "'framework'"},{'id': '301', 'type': 'call', 'children': ['302', '307']},{'id': '302', 'type': 'attribute', 'children': ['303', '306']},{'id': '303', 'type': 'subscript', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'ent'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '307', 'type': 'argument_list', 'children': ['308']},{'id': '308', 'type': 'binary_operator', 'children': ['309', '312'], 'value': '+'},{'id': '309', 'type': 'subscript', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'packages'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '312', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '313', 'type': 'comparison_operator', 'children': ['314', '315'], 'value': '=='},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '316', 'type': 'block', 'children': ['317']},{'id': '317', 'type': 'expression_statement', 'children': ['318']},{'id': '318', 'type': 'assignment', 'children': ['319', '324']},{'id': '319', 'type': 'subscript', 'children': ['320', '323']},{'id': '320', 'type': 'subscript', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'mediation_matrix'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '324', 'type': 'unary_operator', 'children': ['325'], 'value': '-'},{'id': '325', 'type': 'integer', 'children': [], 'value': '1'},{'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', '335']},{'id': '330', 'type': 'subscript', 'children': ['331', '334']},{'id': '331', 'type': 'subscript', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'mediation_matrix'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '335', 'type': 'integer', 'children': [], 'value': '0'},{'id': '336', 'type': 'elif_clause', 'children': ['337', '342']},{'id': '337', 'type': 'comparison_operator', 'children': ['338', '341'], 'value': '=='},{'id': '338', 'type': 'subscript', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '341', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '342', 'type': 'block', 'children': ['343']},{'id': '343', 'type': 'if_statement', 'children': ['344', '354', '364']},{'id': '344', 'type': '()', 'children': ['345']},{'id': '345', 'type': 'boolean_operator', 'children': ['346', '351'], 'value': 'or'},{'id': '346', 'type': 'comparison_operator', 'children': ['347', '350'], 'value': '=='},{'id': '347', 'type': 'subscript', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '350', 'type': 'string', 'children': [], 'value': "'framework'"},{'id': '351', 'type': 'comparison_operator', 'children': ['352', '353'], 'value': '=='},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '354', 'type': 'block', 'children': ['355']},{'id': '355', 'type': 'expression_statement', 'children': ['356']},{'id': '356', 'type': 'assignment', 'children': ['357', '362']},{'id': '357', 'type': 'subscript', 'children': ['358', '361']},{'id': '358', 'type': 'subscript', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'mediation_matrix'},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '362', 'type': 'unary_operator', 'children': ['363'], 'value': '-'},{'id': '363', 'type': 'integer', 'children': [], 'value': '1'},{'id': '364', 'type': 'else_clause', 'children': ['365']},{'id': '365', 'type': 'block', 'children': ['366']},{'id': '366', 'type': 'expression_statement', 'children': ['367']},{'id': '367', 'type': 'assignment', 'children': ['368', '373']},{'id': '368', 'type': 'subscript', 'children': ['369', '372']},{'id': '369', 'type': 'subscript', 'children': ['370', '371']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'mediation_matrix'},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '373', 'type': 'integer', 'children': [], 'value': '0'},{'id': '374', 'type': 'else_clause', 'children': ['375']},{'id': '375', 'type': 'block', 'children': ['376']},{'id': '376', 'type': 'raise_statement', 'children': ['377']},{'id': '377', 'type': 'call', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'DesignStructureMatrixError'},{'id': '379', 'type': 'argument_list', 'children': ['380']},{'id': '380', 'type': 'binary_operator', 'children': ['381', '382'], 'value': '%'},{'id': '381', 'type': 'string', 'children': [], 'value': "'Mediation matrix value NOT generated for %s:%s'"},{'id': '382', 'type': 'tuple', 'children': ['383', '384']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '385', 'type': 'return_statement', 'children': ['386']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'mediation_matrix'}
def generate_mediation_matrix(dsm): cat = dsm.categories ent = dsm.entities size = dsm.size[0] if not cat: cat = ['appmodule'] * size packages = [e.split('.')[0] for e in ent] mediation_matrix = [[0 for _ in range(size)] for _ in range(size)] for i in range(0, size): for j in range(0, size): if cat[i] == 'framework': if cat[j] == 'framework': mediation_matrix[i][j] = -1 else: mediation_matrix[i][j] = 0 elif cat[i] == 'corelib': if (cat[j] in ('framework', 'corelib') or ent[i].startswith(packages[j] + '.') or i == j): mediation_matrix[i][j] = -1 else: mediation_matrix[i][j] = 0 elif cat[i] == 'applib': if (cat[j] in ('framework', 'corelib', 'applib') or ent[i].startswith(packages[j] + '.') or i == j): mediation_matrix[i][j] = -1 else: mediation_matrix[i][j] = 0 elif cat[i] == 'appmodule': if (cat[j] in ('framework', 'corelib', 'applib', 'broker', 'data') or ent[i].startswith(packages[j] + '.') or i == j): mediation_matrix[i][j] = -1 else: mediation_matrix[i][j] = 0 elif cat[i] == 'broker': if (cat[j] in ( 'appmodule', 'corelib', 'framework') or ent[i].startswith(packages[j] + '.') or i == j): mediation_matrix[i][j] = -1 else: mediation_matrix[i][j] = 0 elif cat[i] == 'data': if (cat[j] == 'framework' or i == j): mediation_matrix[i][j] = -1 else: mediation_matrix[i][j] = 0 else: raise DesignStructureMatrixError( 'Mediation matrix value NOT generated for %s:%s' % ( i, j)) return mediation_matrix
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'check'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'dsm'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'independence_factor'},{'id': '8', 'type': 'integer', 'children': [], 'value': '5'},{'id': '9', 'type': 'dictionary_splat_pattern', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '11', 'type': 'block', 'children': ['12', '16', '20', '26', '32', '40', '51', '55', '106', '132', '180']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'least_common_mechanism'},{'id': '15', 'type': 'False', 'children': []},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '19', 'type': 'string', 'children': [], 'value': "''"},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'dsm'},{'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': 'categories'},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'dsm'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'dsm_size'},{'id': '35', 'type': 'subscript', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'dsm'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '39', 'type': 'integer', 'children': [], 'value': '0'},{'id': '40', 'type': 'if_statement', 'children': ['41', '43']},{'id': '41', 'type': 'not_operator', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '47', 'type': 'binary_operator', 'children': ['48', '50'], 'value': '*'},{'id': '48', 'type': 'list', 'children': ['49'], 'value': "['appmodule']"},{'id': '49', 'type': 'string', 'children': [], 'value': "'appmodule'"},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'dsm_size'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'dependent_module_number'},{'id': '54', 'type': 'list', 'children': [], 'value': '[]'},{'id': '55', 'type': 'for_statement', 'children': ['56', '57', '62']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '59', 'type': 'argument_list', 'children': ['60', '61']},{'id': '60', 'type': 'integer', 'children': [], 'value': '0'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'dsm_size'},{'id': '62', 'type': 'block', 'children': ['63', '70']},{'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': 'dependent_module_number'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'integer', 'children': [], 'value': '0'},{'id': '70', 'type': 'for_statement', 'children': ['71', '72', '77']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76']},{'id': '75', 'type': 'integer', 'children': [], 'value': '0'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'dsm_size'},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'if_statement', 'children': ['79', '99']},{'id': '79', 'type': '()', 'children': ['80']},{'id': '80', 'type': 'boolean_operator', 'children': ['81', '92'], 'value': 'and'},{'id': '81', 'type': 'boolean_operator', 'children': ['82', '87'], 'value': 'and'},{'id': '82', 'type': 'comparison_operator', 'children': ['83', '86'], 'value': '!='},{'id': '83', 'type': 'subscript', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '86', 'type': 'string', 'children': [], 'value': "'framework'"},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '91'], 'value': '!='},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '91', 'type': 'string', 'children': [], 'value': "'framework'"},{'id': '92', 'type': 'comparison_operator', 'children': ['93', '98'], 'value': '>'},{'id': '93', 'type': 'subscript', 'children': ['94', '97']},{'id': '94', 'type': 'subscript', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '98', 'type': 'integer', 'children': [], 'value': '0'},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'augmented_assignment', 'children': ['102', '105'], 'value': '+='},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'dependent_module_number'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '105', 'type': 'integer', 'children': [], 'value': '1'},{'id': '106', 'type': 'for_statement', 'children': ['107', '110', '116']},{'id': '107', 'type': 'pattern_list', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'dsm'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'if_statement', 'children': ['118', '125']},{'id': '118', 'type': 'boolean_operator', 'children': ['119', '122'], 'value': 'or'},{'id': '119', 'type': 'comparison_operator', 'children': ['120', '121'], 'value': '=='},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '121', 'type': 'string', 'children': [], 'value': "'broker'"},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': '=='},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '124', 'type': 'string', 'children': [], 'value': "'applib'"},{'id': '125', 'type': 'block', 'children': ['126']},{'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': 'dependent_module_number'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '131', 'type': 'integer', 'children': [], 'value': '0'},{'id': '132', 'type': 'if_statement', 'children': ['133', '141', '146']},{'id': '133', 'type': 'comparison_operator', 'children': ['134', '138'], 'value': '<='},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'dependent_module_number'},{'id': '138', 'type': 'binary_operator', 'children': ['139', '140'], 'value': '/'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'dsm_size'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'independence_factor'},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'least_common_mechanism'},{'id': '145', 'type': 'True', 'children': []},{'id': '146', 'type': 'else_clause', 'children': ['147']},{'id': '147', 'type': 'block', 'children': ['148', '155']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'maximum'},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'dependent_module_number'},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '158', 'type': '()', 'children': ['159']},{'id': '159', 'type': 'binary_operator', 'children': ['160', '163'], 'value': '%'},{'id': '160', 'type': 'concatenated_string', 'children': ['161', '162']},{'id': '161', 'type': 'string', 'children': [], 'value': "'Dependencies to %s (%s) > matrix size (%s) / '"},{'id': '162', 'type': 'string', 'children': [], 'value': "'independence factor (%s) = %s'"},{'id': '163', 'type': 'tuple', 'children': ['164', '174', '175', '176', '177']},{'id': '164', 'type': 'subscript', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'dsm'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'entities'},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'dependent_module_number'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'maximum'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'maximum'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'dsm_size'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'independence_factor'},{'id': '177', 'type': 'binary_operator', 'children': ['178', '179'], 'value': '/'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'dsm_size'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'independence_factor'},{'id': '180', 'type': 'return_statement', 'children': ['181']},{'id': '181', 'type': 'expression_list', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'least_common_mechanism'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'message'}
def check(self, dsm, independence_factor=5, **kwargs): least_common_mechanism = False message = '' data = dsm.data categories = dsm.categories dsm_size = dsm.size[0] if not categories: categories = ['appmodule'] * dsm_size dependent_module_number = [] for j in range(0, dsm_size): dependent_module_number.append(0) for i in range(0, dsm_size): if (categories[i] != 'framework' and categories[j] != 'framework' and data[i][j] > 0): dependent_module_number[j] += 1 for index, item in enumerate(dsm.categories): if item == 'broker' or item == 'applib': dependent_module_number[index] = 0 if max(dependent_module_number) <= dsm_size / independence_factor: least_common_mechanism = True else: maximum = max(dependent_module_number) message = ( 'Dependencies to %s (%s) > matrix size (%s) / ' 'independence factor (%s) = %s' % ( dsm.entities[dependent_module_number.index(maximum)], maximum, dsm_size, independence_factor, dsm_size / independence_factor)) return least_common_mechanism, message
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'abstract'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'class_'},{'id': '5', 'type': 'block', 'children': ['6', '20', '24', '31', '63', '69']},{'id': '6', 'type': 'if_statement', 'children': ['7', '14']},{'id': '7', 'type': 'not_operator', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'isclass'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'class_'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'raise_statement', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'string', 'children': [], 'value': '"@abstract can only be applied to classes"'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'abc_meta'},{'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': 'class_meta'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'class_'},{'id': '31', 'type': 'if_statement', 'children': ['32', '37']},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'not'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'class_meta'},{'id': '34', 'type': 'tuple', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_ABCMetaclass'},{'id': '36', 'type': 'identifier', 'children': [], 'value': '_ABCObjectMetaclass'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'if_statement', 'children': ['39', '42', '47', '56']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'is'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'class_meta'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'type'},{'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': 'abc_meta'},{'id': '46', 'type': 'identifier', 'children': [], 'value': '_ABCMetaclass'},{'id': '47', 'type': 'elif_clause', 'children': ['48', '51']},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': 'is'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'class_meta'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'ObjectMetaclass'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'abc_meta'},{'id': '55', 'type': 'identifier', 'children': [], 'value': '_ABCObjectMetaclass'},{'id': '56', 'type': 'else_clause', 'children': ['57']},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'raise_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'string', 'children': [], 'value': '"@abstract cannot be applied to classes with custom metaclass"'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'class_'},{'id': '67', 'type': 'identifier', 'children': [], 'value': '__abstract__'},{'id': '68', 'type': 'True', 'children': []},{'id': '69', 'type': 'return_statement', 'children': ['70']},{'id': '70', 'type': 'conditional_expression', 'children': ['71', '78', '79'], 'value': 'if'},{'id': '71', 'type': 'call', 'children': ['72', '76']},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'metaclass'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'abc_meta'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'class_'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'abc_meta'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'class_'}
def abstract(class_): if not inspect.isclass(class_): raise TypeError("@abstract can only be applied to classes") abc_meta = None class_meta = type(class_) if class_meta not in (_ABCMetaclass, _ABCObjectMetaclass): if class_meta is type: abc_meta = _ABCMetaclass elif class_meta is ObjectMetaclass: abc_meta = _ABCObjectMetaclass else: raise ValueError( "@abstract cannot be applied to classes with custom metaclass") class_.__abstract__ = True return metaclass(abc_meta)(class_) if abc_meta else class_
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'final'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '5', 'type': 'block', 'children': ['6', '41', '54', '60']},{'id': '6', 'type': 'if_statement', 'children': ['7', '13', '29']},{'id': '7', 'type': 'call', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'isclass'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'if_statement', 'children': ['15', '21']},{'id': '15', 'type': 'not_operator', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '18', 'type': 'argument_list', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'ObjectMetaclass'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'raise_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'concatenated_string', 'children': ['27', '28']},{'id': '27', 'type': 'string', 'children': [], 'value': '"@final can only be applied to a class "'},{'id': '28', 'type': 'string', 'children': [], 'value': '"that is a subclass of Object"'},{'id': '29', 'type': 'elif_clause', 'children': ['30', '35']},{'id': '30', 'type': 'not_operator', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'is_method'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'raise_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'string', 'children': [], 'value': '"@final can only be applied to classes or methods"'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '44', 'type': 'conditional_expression', 'children': ['45', '48', '53'], 'value': 'if'},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '52', 'type': 'identifier', 'children': [], 'value': '_WrappedMethod'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '58', 'type': 'identifier', 'children': [], 'value': '__final__'},{'id': '59', 'type': 'True', 'children': []},{'id': '60', 'type': 'return_statement', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'arg'}
def final(arg): if inspect.isclass(arg): if not isinstance(arg, ObjectMetaclass): raise ValueError("@final can only be applied to a class " "that is a subclass of Object") elif not is_method(arg): raise TypeError("@final can only be applied to classes or methods") method = arg.method if isinstance(arg, _WrappedMethod) else arg method.__final__ = True return arg
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'override'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ABSENT'},{'id': '7', 'type': 'block', 'children': ['8', '12', '45', '55', '71']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '12', 'type': 'if_statement', 'children': ['13', '25']},{'id': '13', 'type': 'boolean_operator', 'children': ['14', '20'], 'value': 'or'},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'isfunction'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'arg'},{'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': 'arg'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'NonInstanceMethod'},{'id': '25', 'type': 'block', 'children': ['26', '33', '40']},{'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': '_OverrideDecorator'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'maybe_signal_classmethod'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'decorator'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': '_OverrideDecorator'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'None', 'children': []},{'id': '40', 'type': 'return_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'decorator'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '45', 'type': 'if_statement', 'children': ['46', '49']},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': 'is'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'ABSENT'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'return_statement', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': '_OverrideDecorator'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'None', 'children': []},{'id': '55', 'type': 'if_statement', 'children': ['56', '65']},{'id': '56', 'type': 'boolean_operator', 'children': ['57', '61'], 'value': 'or'},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'is_class'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'is_string'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'return_statement', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': '_OverrideDecorator'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '71', 'type': 'raise_statement', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'concatenated_string', 'children': ['76', '77']},{'id': '76', 'type': 'string', 'children': [], 'value': '"explicit base class for @override "'},{'id': '77', 'type': 'string', 'children': [], 'value': '"must be either a string or a class object"'}
def override(base=ABSENT): arg = base if inspect.isfunction(arg) or isinstance(arg, NonInstanceMethod): _OverrideDecorator.maybe_signal_classmethod(arg) decorator = _OverrideDecorator(None) return decorator(arg) if arg is ABSENT: return _OverrideDecorator(None) if is_class(arg) or is_string(arg): return _OverrideDecorator(arg) raise TypeError("explicit base class for @override " "must be either a string or a class object")
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_index'},{'id': '3', 'type': 'parameters', 'children': ['4', '6']},{'id': '4', 'type': 'list_splat_pattern', 'children': ['5']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '8', 'type': 'block', 'children': ['9', '19', '29', '143', '150', '164', '168']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'string', 'children': [], 'value': "'start'"},{'id': '18', 'type': 'integer', 'children': [], 'value': '0'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'step'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'string', 'children': [], 'value': "'step'"},{'id': '28', 'type': 'integer', 'children': [], 'value': '1'},{'id': '29', 'type': 'if_statement', 'children': ['30', '36', '57']},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '35'], 'value': '=='},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '35', 'type': 'integer', 'children': [], 'value': '2'},{'id': '36', 'type': 'block', 'children': ['37', '43', '48']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '42']},{'id': '39', 'type': 'pattern_list', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'list_'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'ensure_sequence'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'list_'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'predicate'},{'id': '51', 'type': 'lambda', 'children': ['52', '54']},{'id': '52', 'type': 'lambda_parameters', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': '=='},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '57', 'type': 'else_clause', 'children': ['58']},{'id': '58', 'type': 'block', 'children': ['59', '73', '87', '103', '112']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'ensure_keyword_args'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64', '68']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'mandatory'},{'id': '66', 'type': 'tuple', 'children': ['67']},{'id': '67', 'type': 'string', 'children': [], 'value': "'in_'"},{'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'optional'},{'id': '70', 'type': 'tuple', 'children': ['71', '72']},{'id': '71', 'type': 'string', 'children': [], 'value': "'of'"},{'id': '72', 'type': 'string', 'children': [], 'value': "'where'"},{'id': '73', 'type': 'if_statement', 'children': ['74', '81']},{'id': '74', 'type': 'boolean_operator', 'children': ['75', '78'], 'value': 'and'},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'in'},{'id': '76', 'type': 'string', 'children': [], 'value': "'of'"},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': 'in'},{'id': '79', 'type': 'string', 'children': [], 'value': "'where'"},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'raise_statement', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'string', 'children': [], 'value': '"either an item or predicate must be supplied, not both"'},{'id': '87', 'type': 'if_statement', 'children': ['88', '97']},{'id': '88', 'type': 'not_operator', 'children': ['89']},{'id': '89', 'type': '()', 'children': ['90']},{'id': '90', 'type': 'boolean_operator', 'children': ['91', '94'], 'value': 'or'},{'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': 'in'},{'id': '92', 'type': 'string', 'children': [], 'value': "'of'"},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': 'in'},{'id': '95', 'type': 'string', 'children': [], 'value': "'where'"},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'raise_statement', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'string', 'children': [], 'value': '"an item or predicate must be supplied"'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'list_'},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'ensure_sequence'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'subscript', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '111', 'type': 'string', 'children': [], 'value': "'in_'"},{'id': '112', 'type': 'if_statement', 'children': ['113', '116', '126']},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': 'in'},{'id': '114', 'type': 'string', 'children': [], 'value': "'where'"},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'predicate'},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'ensure_callable'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '125', 'type': 'string', 'children': [], 'value': "'where'"},{'id': '126', 'type': 'else_clause', 'children': ['127']},{'id': '127', 'type': 'block', 'children': ['128', '134']},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '131', 'type': 'subscript', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '133', 'type': 'string', 'children': [], 'value': "'of'"},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'predicate'},{'id': '137', 'type': 'lambda', 'children': ['138', '140']},{'id': '138', 'type': 'lambda_parameters', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '140', 'type': 'comparison_operator', 'children': ['141', '142'], 'value': '=='},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'len_'},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'list_'},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '155', 'type': 'argument_list', 'children': ['156', '157']},{'id': '156', 'type': 'integer', 'children': [], 'value': '0'},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '159', 'type': 'argument_list', 'children': ['160', '163']},{'id': '160', 'type': 'binary_operator', 'children': ['161', '162'], 'value': '-'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'len_'},{'id': '162', 'type': 'integer', 'children': [], 'value': '1'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '168', 'type': 'while_statement', 'children': ['169', '173', '190']},{'id': '169', 'type': 'comparison_operator', 'children': ['170', '171', '172'], 'value': '<='},{'id': '170', 'type': 'integer', 'children': [], 'value': '0'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'len_'},{'id': '173', 'type': 'block', 'children': ['174', '186']},{'id': '174', 'type': 'if_statement', 'children': ['175', '181']},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'predicate'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'subscript', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'list_'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'return_statement', 'children': ['183']},{'id': '183', 'type': 'expression_list', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'list_'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'augmented_assignment', 'children': ['188', '189'], 'value': '+='},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'step'},{'id': '190', 'type': 'else_clause', 'children': ['191']},{'id': '191', 'type': 'block', 'children': ['192']},{'id': '192', 'type': 'return_statement', 'children': ['193']},{'id': '193', 'type': 'expression_list', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'list_'},{'id': '195', 'type': 'unary_operator', 'children': ['196'], 'value': '-'},{'id': '196', 'type': 'integer', 'children': [], 'value': '1'}
def _index(*args, **kwargs): start = kwargs.pop('start', 0) step = kwargs.pop('step', 1) if len(args) == 2: elem, list_ = args ensure_sequence(list_) predicate = lambda item: item == elem else: ensure_keyword_args(kwargs, mandatory=('in_',), optional=('of', 'where')) if 'of' in kwargs and 'where' in kwargs: raise TypeError( "either an item or predicate must be supplied, not both") if not ('of' in kwargs or 'where' in kwargs): raise TypeError("an item or predicate must be supplied") list_ = ensure_sequence(kwargs['in_']) if 'where' in kwargs: predicate = ensure_callable(kwargs['where']) else: elem = kwargs['of'] predicate = lambda item: item == elem len_ = len(list_) start = max(0, min(len_ - 1, start)) i = start while 0 <= i < len_: if predicate(list_[i]): return list_, i i += step else: return list_, -1
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'tally_poll'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '5', 'type': 'block', 'children': ['6', '14', '26', '35', '45', '52', '63', '87', '104', '113', '130', '170', '176', '185', '211', '218', '226']},{'id': '6', 'type': 'if_statement', 'children': ['7', '11']},{'id': '7', 'type': 'not_operator', 'children': ['8']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'return_statement', 'children': ['13']},{'id': '13', 'type': 'string', 'children': [], 'value': '"Syntax: !vote tally <pollnum>"'},{'id': '14', 'type': 'if_statement', 'children': ['15', '23']},{'id': '15', 'type': 'not_operator', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '22']},{'id': '17', 'type': 'attribute', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'isdigit'},{'id': '22', 'type': 'argument_list', 'children': []},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'string', 'children': [], 'value': '"Not A Valid Positive Integer."'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'pid'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'poll'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'get_open_poll'},{'id': '40', 'type': 'argument_list', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'pid'},{'id': '45', 'type': 'if_statement', 'children': ['46', '49']},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': 'is'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'poll'},{'id': '48', 'type': 'None', 'children': []},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'return_statement', 'children': ['51']},{'id': '51', 'type': 'string', 'children': [], 'value': '"That poll doesn\'t exist or was deleted. Use !poll list to see valid polls"'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '55', 'type': 'conditional_expression', 'children': ['56', '57', '62'], 'value': 'if'},{'id': '56', 'type': 'string', 'children': [], 'value': '"Active"'},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '61'], 'value': '=='},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'poll'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'active'},{'id': '61', 'type': 'integer', 'children': [], 'value': '1'},{'id': '62', 'type': 'string', 'children': [], 'value': '"Closed"'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'votes'},{'id': '66', 'type': 'call', 'children': ['67', '86']},{'id': '67', 'type': 'attribute', 'children': ['68', '85']},{'id': '68', 'type': 'call', 'children': ['69', '79']},{'id': '69', 'type': 'attribute', 'children': ['70', '78']},{'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': 'args'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'Poll_responses'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'comparison_operator', 'children': ['81', '84'], 'value': '=='},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'Poll_responses'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'pid'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'pid'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '86', 'type': 'argument_list', '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': 'args'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'binary_operator', 'children': ['94', '95'], 'value': '%'},{'id': '94', 'type': 'string', 'children': [], 'value': '"%s poll: %s, %d total votes"'},{'id': '95', 'type': 'tuple', 'children': ['96', '97', '100']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'poll'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'question'},{'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': 'votes'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'votemap'},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '113', 'type': 'for_statement', 'children': ['114', '115', '116']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'votes'},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '126']},{'id': '119', 'type': 'attribute', 'children': ['120', '125']},{'id': '120', 'type': 'subscript', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'votemap'},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'voter'},{'id': '130', 'type': 'for_statement', 'children': ['131', '132', '140']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'votemap'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '139', 'type': 'argument_list', 'children': []},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '146', 'type': 'argument_list', 'children': ['147', '165']},{'id': '147', 'type': 'binary_operator', 'children': ['148', '149'], 'value': '%'},{'id': '148', 'type': 'string', 'children': [], 'value': '"%s: %d -- %s"'},{'id': '149', 'type': 'tuple', 'children': ['150', '151', '157']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'subscript', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'votemap'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'string', 'children': [], 'value': '", "'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'subscript', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'votemap'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '165', 'type': 'keyword_argument', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '170', 'type': 'if_statement', 'children': ['171', '173']},{'id': '171', 'type': 'not_operator', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'votemap'},{'id': '173', 'type': 'block', 'children': ['174']},{'id': '174', 'type': 'return_statement', 'children': ['175']},{'id': '175', 'type': 'string', 'children': [], 'value': '""'},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'ranking'},{'id': '179', 'type': 'call', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '185', 'type': 'for_statement', 'children': ['186', '187', '192']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'votemap'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '191', 'type': 'argument_list', 'children': []},{'id': '192', 'type': 'block', 'children': ['193', '202']},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '196', 'type': 'call', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'subscript', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'votemap'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'call', 'children': ['204', '209']},{'id': '204', 'type': 'attribute', 'children': ['205', '208']},{'id': '205', 'type': 'subscript', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'ranking'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'high'},{'id': '214', 'type': 'call', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'ranking'},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'assignment', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'winners'},{'id': '221', 'type': 'tuple', 'children': ['222', '225']},{'id': '222', 'type': 'subscript', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'ranking'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'high'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'high'},{'id': '226', 'type': 'if_statement', 'children': ['227', '235', '250']},{'id': '227', 'type': 'comparison_operator', 'children': ['228', '234'], 'value': '=='},{'id': '228', 'type': 'call', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '230', 'type': 'argument_list', 'children': ['231']},{'id': '231', 'type': 'subscript', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'winners'},{'id': '233', 'type': 'integer', 'children': [], 'value': '0'},{'id': '234', 'type': 'integer', 'children': [], 'value': '1'},{'id': '235', 'type': 'block', 'children': ['236', '246']},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'assignment', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'winners'},{'id': '239', 'type': 'tuple', 'children': ['240', '245']},{'id': '240', 'type': 'subscript', 'children': ['241', '244']},{'id': '241', 'type': 'subscript', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'winners'},{'id': '243', 'type': 'integer', 'children': [], 'value': '0'},{'id': '244', 'type': 'integer', 'children': [], 'value': '0'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'high'},{'id': '246', 'type': 'return_statement', 'children': ['247']},{'id': '247', 'type': 'binary_operator', 'children': ['248', '249'], 'value': '%'},{'id': '248', 'type': 'string', 'children': [], 'value': '"The winner is %s with %d votes."'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'winners'},{'id': '250', 'type': 'else_clause', 'children': ['251']},{'id': '251', 'type': 'block', 'children': ['252', '265']},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'assignment', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'winners'},{'id': '255', 'type': 'tuple', 'children': ['256', '264']},{'id': '256', 'type': 'call', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'string', 'children': [], 'value': '", "'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '260', 'type': 'argument_list', 'children': ['261']},{'id': '261', 'type': 'subscript', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'winners'},{'id': '263', 'type': 'integer', 'children': [], 'value': '0'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'high'},{'id': '265', 'type': 'return_statement', 'children': ['266']},{'id': '266', 'type': 'binary_operator', 'children': ['267', '268'], 'value': '%'},{'id': '267', 'type': 'string', 'children': [], 'value': '"Tie between %s with %d votes."'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'winners'}
def tally_poll(args): if not args.msg: return "Syntax: !vote tally <pollnum>" if not args.msg.isdigit(): return "Not A Valid Positive Integer." pid = int(args.msg) poll = get_open_poll(args.session, pid) if poll is None: return "That poll doesn't exist or was deleted. Use !poll list to see valid polls" state = "Active" if poll.active == 1 else "Closed" votes = args.session.query(Poll_responses).filter(Poll_responses.pid == pid).all() args.send("%s poll: %s, %d total votes" % (state, poll.question, len(votes))) votemap = collections.defaultdict(list) for v in votes: votemap[v.response].append(v.voter) for x in sorted(votemap.keys()): args.send("%s: %d -- %s" % (x, len(votemap[x]), ", ".join(votemap[x])), target=args.nick) if not votemap: return "" ranking = collections.defaultdict(list) for x in votemap.keys(): num = len(votemap[x]) ranking[num].append(x) high = max(ranking) winners = (ranking[high], high) if len(winners[0]) == 1: winners = (winners[0][0], high) return "The winner is %s with %d votes." % winners else: winners = (", ".join(winners[0]), high) return "Tie between %s with %d votes." % winners
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_setup_pages'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '6', 'type': 'block', 'children': ['7', '13', '19', '25', '31', '38', '42', '46', '80', '90', '102']},{'id': '7', 'type': 'import_from_statement', 'children': ['8', '11']},{'id': '8', 'type': 'dotted_name', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'cms'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '11', 'type': 'dotted_name', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'NoHomeFound'},{'id': '13', 'type': 'import_from_statement', 'children': ['14', '17']},{'id': '14', 'type': 'dotted_name', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'cms'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '17', 'type': 'dotted_name', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'Page'},{'id': '19', 'type': 'import_from_statement', 'children': ['20', '23']},{'id': '20', 'type': 'dotted_name', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'cms'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '23', 'type': 'dotted_name', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'get_language_list'},{'id': '25', 'type': 'import_from_statement', 'children': ['26', '29']},{'id': '26', 'type': 'dotted_name', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'django'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '29', 'type': 'dotted_name', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '31', 'type': 'import_from_statement', 'children': ['32', '36']},{'id': '32', 'type': 'dotted_name', 'children': ['33', '34', '35']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'django'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'translation'},{'id': '36', 'type': 'dotted_name', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'override'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'app_page'},{'id': '41', 'type': 'None', 'children': []},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'get_url'},{'id': '45', 'type': 'False', 'children': []},{'id': '46', 'type': 'if_statement', 'children': ['47', '53']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51', '52']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '51', 'type': 'string', 'children': [], 'value': "'ALDRYN_SEARCH_CMS_PAGE'"},{'id': '52', 'type': 'False', 'children': []},{'id': '53', 'type': 'block', 'children': ['54', '60', '68', '74']},{'id': '54', 'type': 'import_from_statement', 'children': ['55', '58']},{'id': '55', 'type': 'dotted_name', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'aldryn_search'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'search_indexes'},{'id': '58', 'type': 'dotted_name', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'TitleIndex'},{'id': '60', 'type': 'function_definition', 'children': ['61', '62', '65']},{'id': '61', 'type': 'function_name', 'children': [], 'value': 'fake_url'},{'id': '62', 'type': 'parameters', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'return_statement', 'children': ['67']},{'id': '67', 'type': 'string', 'children': [], 'value': "''"},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'get_url'},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'TitleIndex'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'get_url'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'TitleIndex'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'get_url'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'fake_url'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'site'},{'id': '83', 'type': 'call', 'children': ['84', '89']},{'id': '84', 'type': 'attribute', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'Site'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'get_current'},{'id': '89', 'type': 'argument_list', 'children': []},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'auto_sites'},{'id': '93', 'type': 'call', 'children': ['94', '99']},{'id': '94', 'type': 'attribute', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'auto_setup'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101']},{'id': '100', 'type': 'string', 'children': [], 'value': "'sites'"},{'id': '101', 'type': 'True', 'children': []},{'id': '102', 'type': 'if_statement', 'children': ['103', '112']},{'id': '103', 'type': 'boolean_operator', 'children': ['104', '107'], 'value': 'or'},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '106'], 'value': 'is'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'auto_sites'},{'id': '106', 'type': 'True', 'children': []},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '111'], 'value': 'in'},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'site'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'auto_sites'},{'id': '112', 'type': 'block', 'children': ['113', '159', '168']},{'id': '113', 'type': 'if_statement', 'children': ['114', '120']},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118', '119']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '118', 'type': 'string', 'children': [], 'value': "'app_config'"},{'id': '119', 'type': 'False', 'children': []},{'id': '120', 'type': 'block', 'children': ['121', '133']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'configs'},{'id': '124', 'type': 'call', 'children': ['125', '132']},{'id': '125', 'type': 'attribute', 'children': ['126', '131']},{'id': '126', 'type': 'attribute', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'app_config'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '132', 'type': 'argument_list', 'children': []},{'id': '133', 'type': 'if_statement', 'children': ['134', '140', '149']},{'id': '134', 'type': 'not_operator', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'configs'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '139', 'type': 'argument_list', 'children': []},{'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': 'config'},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '147', 'type': 'identifier', 'children': [], 'value': '_create_config'},{'id': '148', 'type': 'argument_list', 'children': []},{'id': '149', 'type': 'else_clause', 'children': ['150']},{'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': 'config'},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'configs'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '158', 'type': 'argument_list', 'children': []},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'langs'},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'get_language_list'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'site'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '168', 'type': 'if_statement', 'children': ['169', '193']},{'id': '169', 'type': 'not_operator', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '192']},{'id': '171', 'type': 'attribute', 'children': ['172', '191']},{'id': '172', 'type': 'call', 'children': ['173', '185']},{'id': '173', 'type': 'attribute', 'children': ['174', '184']},{'id': '174', 'type': 'call', 'children': ['175', '180']},{'id': '175', 'type': 'attribute', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'Page'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'on_site'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'site'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'keyword_argument', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'application_urls'},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '190', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '192', 'type': 'argument_list', 'children': []},{'id': '193', 'type': 'block', 'children': ['194', '325']},{'id': '194', 'type': 'for_statement', 'children': ['195', '196', '197']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'lang'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'langs'},{'id': '197', 'type': 'block', 'children': ['198']},{'id': '198', 'type': 'with_statement', 'children': ['199', '205']},{'id': '199', 'type': 'with_clause', 'children': ['200']},{'id': '200', 'type': 'with_item', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'override'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'lang'},{'id': '205', 'type': 'block', 'children': ['206', '247', '273', '281', '302']},{'id': '206', 'type': 'if_statement', 'children': ['207', '208', '230', '241']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '208', 'type': 'block', 'children': ['209', '224']},{'id': '209', 'type': 'if_statement', 'children': ['210', '215']},{'id': '210', 'type': 'subscript', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'auto_setup'},{'id': '214', 'type': 'string', 'children': [], 'value': "'config_translated_fields'"},{'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': 'cls'},{'id': '220', 'type': 'identifier', 'children': [], 'value': '_create_config_translation'},{'id': '221', 'type': 'argument_list', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'lang'},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'namespace'},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'namespace'},{'id': '230', 'type': 'elif_clause', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'app_name'},{'id': '234', 'type': 'block', 'children': ['235']},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'namespace'},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'app_name'},{'id': '241', 'type': 'else_clause', 'children': ['242']},{'id': '242', 'type': 'block', 'children': ['243']},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'assignment', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'namespace'},{'id': '246', 'type': 'None', 'children': []},{'id': '247', 'type': 'try_statement', 'children': ['248', '266']},{'id': '248', 'type': 'block', 'children': ['249']},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'assignment', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'home'},{'id': '252', 'type': 'call', 'children': ['253', '265']},{'id': '253', 'type': 'attribute', 'children': ['254', '264']},{'id': '254', 'type': 'call', 'children': ['255', '260']},{'id': '255', 'type': 'attribute', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'Page'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'get_home'},{'id': '260', 'type': 'argument_list', 'children': ['261']},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'site'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'get_draft_object'},{'id': '265', 'type': 'argument_list', 'children': []},{'id': '266', 'type': 'except_clause', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'NoHomeFound'},{'id': '268', 'type': 'block', 'children': ['269']},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'assignment', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'home'},{'id': '272', 'type': 'None', 'children': []},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'assignment', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'set_home'},{'id': '276', 'type': 'call', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '278', 'type': 'argument_list', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'Page'},{'id': '280', 'type': 'string', 'children': [], 'value': "'set_as_homepage'"},{'id': '281', 'type': 'expression_statement', 'children': ['282']},{'id': '282', 'type': 'assignment', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'home'},{'id': '284', 'type': 'call', 'children': ['285', '288']},{'id': '285', 'type': 'attribute', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '287', 'type': 'identifier', 'children': [], 'value': '_create_page'},{'id': '288', 'type': 'argument_list', 'children': ['289', '290', '291', '296', '299']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'home'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'lang'},{'id': '291', 'type': 'subscript', 'children': ['292', '295']},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'auto_setup'},{'id': '295', 'type': 'string', 'children': [], 'value': "'home title'"},{'id': '296', 'type': 'keyword_argument', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'site'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'site'},{'id': '299', 'type': 'keyword_argument', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'set_home'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'set_home'},{'id': '302', 'type': 'expression_statement', 'children': ['303']},{'id': '303', 'type': 'assignment', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'app_page'},{'id': '305', 'type': 'call', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '308', 'type': 'identifier', 'children': [], 'value': '_create_page'},{'id': '309', 'type': 'argument_list', 'children': ['310', '311', '312', '317', '320', '321', '322']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'app_page'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'lang'},{'id': '312', 'type': 'subscript', 'children': ['313', '316']},{'id': '313', 'type': 'attribute', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'auto_setup'},{'id': '316', 'type': 'string', 'children': [], 'value': "'page title'"},{'id': '317', 'type': 'attribute', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '319', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'home'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'namespace'},{'id': '322', 'type': 'keyword_argument', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'site'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'site'},{'id': '325', 'type': 'if_statement', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'get_url'},{'id': '327', 'type': 'block', 'children': ['328']},{'id': '328', 'type': 'expression_statement', 'children': ['329']},{'id': '329', 'type': 'assignment', 'children': ['330', '333']},{'id': '330', 'type': 'attribute', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'TitleIndex'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'get_url'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'get_url'}
def _setup_pages(cls, config): from cms.exceptions import NoHomeFound from cms.models import Page from cms.utils import get_language_list from django.conf import settings from django.utils.translation import override app_page = None get_url = False if getattr(settings, 'ALDRYN_SEARCH_CMS_PAGE', False): from aldryn_search.search_indexes import TitleIndex def fake_url(self, obj): return '' get_url = TitleIndex.get_url TitleIndex.get_url = fake_url site = Site.objects.get_current() auto_sites = cls.auto_setup.get('sites', True) if auto_sites is True or site.pk in auto_sites: if getattr(cls, 'app_config', False): configs = cls.app_config.objects.all() if not configs.exists(): config = cls._create_config() else: config = configs.first() langs = get_language_list(site.pk) if not Page.objects.on_site(site.pk).filter(application_urls=cls.__name__).exists(): for lang in langs: with override(lang): if config: if cls.auto_setup['config_translated_fields']: cls._create_config_translation(config, lang) namespace = config.namespace elif cls.app_name: namespace = cls.app_name else: namespace = None try: home = Page.objects.get_home(site.pk).get_draft_object() except NoHomeFound: home = None set_home = hasattr(Page, 'set_as_homepage') home = cls._create_page( home, lang, cls.auto_setup['home title'], site=site, set_home=set_home ) app_page = cls._create_page( app_page, lang, cls.auto_setup['page title'], cls.__name__, home, namespace, site=site ) if get_url: TitleIndex.get_url = get_url
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'pretty_description'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'wrap_at'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '10', 'type': 'integer', 'children': [], 'value': '0'},{'id': '11', 'type': 'block', 'children': ['12', '45', '51', '71', '75', '101', '111', '123', '139', '143', '239']},{'id': '12', 'type': 'if_statement', 'children': ['13', '20']},{'id': '13', 'type': 'boolean_operator', 'children': ['14', '17'], 'value': 'or'},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'is'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'wrap_at'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': '<'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'wrap_at'},{'id': '19', 'type': 'integer', 'children': [], 'value': '0'},{'id': '20', 'type': 'block', 'children': ['21', '30']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'console_width'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '29', 'type': 'integer', 'children': [], 'value': '79'},{'id': '30', 'type': 'if_statement', 'children': ['31', '34', '39']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'is'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'wrap_at'},{'id': '33', 'type': 'None', 'children': []},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'wrap_at'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '39', 'type': 'else_clause', 'children': ['40']},{'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': 'wrap_at'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '48', 'type': 'binary_operator', 'children': ['49', '50'], 'value': '*'},{'id': '49', 'type': 'string', 'children': [], 'value': "' '"},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'text_wrapper'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'textwrap'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'TextWrapper'},{'id': '58', 'type': 'argument_list', 'children': ['59', '62', '65', '68']},{'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'wrap_at'},{'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'replace_whitespace'},{'id': '64', 'type': 'False', 'children': []},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'initial_indent'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'subsequent_indent'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'new_desc'},{'id': '74', 'type': 'list', 'children': [], 'value': '[]'},{'id': '75', 'type': 'for_statement', 'children': ['76', '77', '83']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'string', 'children': [], 'value': "'\\n'"},{'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': 'new_desc'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '100']},{'id': '91', 'type': 'attribute', 'children': ['92', '99']},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '96', 'type': 'argument_list', 'children': ['97', '98']},{'id': '97', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '98', 'type': 'string', 'children': [], 'value': "''"},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '100', 'type': 'argument_list', 'children': []},{'id': '101', 'type': 'while_statement', 'children': ['102', '106']},{'id': '102', 'type': 'not_operator', 'children': ['103']},{'id': '103', 'type': 'subscript', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'new_desc'},{'id': '105', 'type': 'integer', 'children': [], 'value': '0'},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'delete_statement', 'children': ['108']},{'id': '108', 'type': 'subscript', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'new_desc'},{'id': '110', 'type': 'integer', 'children': [], 'value': '0'},{'id': '111', 'type': 'while_statement', 'children': ['112', '117']},{'id': '112', 'type': 'not_operator', 'children': ['113']},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'new_desc'},{'id': '115', 'type': 'unary_operator', 'children': ['116'], 'value': '-'},{'id': '116', 'type': 'integer', 'children': [], 'value': '1'},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'delete_statement', 'children': ['119']},{'id': '119', 'type': 'subscript', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'new_desc'},{'id': '121', 'type': 'unary_operator', 'children': ['122'], 'value': '-'},{'id': '122', 'type': 'integer', 'children': [], 'value': '1'},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'separators'},{'id': '126', 'type': 'list_comprehension', 'children': ['127', '128', '136']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '128', 'type': 'for_in_clause', 'children': ['129', '132']},{'id': '129', 'type': 'pattern_list', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'new_desc'},{'id': '136', 'type': 'if_clause', 'children': ['137']},{'id': '137', 'type': 'not_operator', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'paragraphs'},{'id': '142', 'type': 'list', 'children': [], 'value': '[]'},{'id': '143', 'type': 'if_statement', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'separators'},{'id': '145', 'type': 'block', 'children': ['146', '156', '168', '206', '219']},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '151']},{'id': '148', 'type': 'pattern_list', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '151', 'type': 'expression_list', 'children': ['152', '153']},{'id': '152', 'type': 'integer', 'children': [], 'value': '0'},{'id': '153', 'type': 'subscript', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'separators'},{'id': '155', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'paragraphs'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'subscript', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'new_desc'},{'id': '164', 'type': 'slice', 'children': ['165', '166', '167']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '166', 'type': 'colon', 'children': []},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '168', 'type': 'for_statement', 'children': ['169', '170', '179']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '170', 'type': 'call', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'binary_operator', 'children': ['174', '178'], 'value': '-'},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'separators'},{'id': '178', 'type': 'integer', 'children': [], 'value': '1'},{'id': '179', 'type': 'block', 'children': ['180', '186', '194']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '183', 'type': 'binary_operator', 'children': ['184', '185'], 'value': '+'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '185', 'type': 'integer', 'children': [], 'value': '1'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '189', 'type': 'subscript', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'separators'},{'id': '191', 'type': 'binary_operator', 'children': ['192', '193'], 'value': '+'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '193', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'paragraphs'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'subscript', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'new_desc'},{'id': '202', 'type': 'slice', 'children': ['203', '204', '205']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '204', 'type': 'colon', 'children': []},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'end'},{'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': 'paragraphs'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'subscript', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'new_desc'},{'id': '214', 'type': 'slice', 'children': ['215', '218']},{'id': '215', 'type': 'binary_operator', 'children': ['216', '217'], 'value': '+'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '217', 'type': 'integer', 'children': [], 'value': '1'},{'id': '218', 'type': 'colon', 'children': []},{'id': '219', 'type': 'return_statement', 'children': ['220']},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'string', 'children': [], 'value': "'\\n\\n'"},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '224', 'type': 'generator_expression', 'children': ['225', '236']},{'id': '225', 'type': 'call', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'text_wrapper'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'fill'},{'id': '229', 'type': 'argument_list', 'children': ['230']},{'id': '230', 'type': 'call', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'string', 'children': [], 'value': "' '"},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '236', 'type': 'for_in_clause', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'paragraphs'},{'id': '239', 'type': 'return_statement', 'children': ['240']},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'text_wrapper'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'fill'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'call', 'children': ['246', '249']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'string', 'children': [], 'value': "' '"},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '249', 'type': 'argument_list', 'children': ['250']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'new_desc'}
def pretty_description(description, wrap_at=None, indent=0): if wrap_at is None or wrap_at < 0: width = console_width(default=79) if wrap_at is None: wrap_at = width else: wrap_at += width indent = ' ' * indent text_wrapper = textwrap.TextWrapper( width=wrap_at, replace_whitespace=False, initial_indent=indent, subsequent_indent=indent) new_desc = [] for line in description.split('\n'): new_desc.append(line.replace('\n', '').strip()) while not new_desc[0]: del new_desc[0] while not new_desc[-1]: del new_desc[-1] separators = [i for i, l in enumerate(new_desc) if not l] paragraphs = [] if separators: start, end = 0, separators[0] paragraphs.append(new_desc[start:end]) for i in range(len(separators) - 1): start = end + 1 end = separators[i + 1] paragraphs.append(new_desc[start:end]) paragraphs.append(new_desc[end + 1:]) return '\n\n'.join(text_wrapper.fill(' '.join(p)) for p in paragraphs) return text_wrapper.fill(' '.join(new_desc))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'search'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '10', '13', '16']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '7', 'type': 'attribute', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'Categories'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'ALL'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'pages'},{'id': '12', 'type': 'integer', 'children': [], 'value': '1'},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'block', 'children': ['20', '26', '47']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'Search'},{'id': '25', 'type': 'argument_list', 'children': []},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '31', 'type': 'argument_list', 'children': ['32', '35', '38', '41', '44']},{'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'pages'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'pages'},{'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '47', 'type': 'return_statement', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 's'}
def search(term, category=Categories.ALL, pages=1, sort=None, order=None): s = Search() s.search(term=term, category=category, pages=pages, sort=sort, order=order) return s
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'popular'},{'id': '3', 'type': 'parameters', 'children': ['4', '7']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sortOption'},{'id': '9', 'type': 'string', 'children': [], 'value': '"title"'},{'id': '10', 'type': 'block', 'children': ['11', '17', '25']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'Search'},{'id': '16', 'type': 'argument_list', 'children': []},{'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': 's'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'popular'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'sortOption'},{'id': '25', 'type': 'return_statement', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 's'}
def popular(category=None, sortOption = "title"): s = Search() s.popular(category, sortOption) return s
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'recent'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'pages'},{'id': '9', 'type': 'integer', 'children': [], 'value': '1'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'block', 'children': ['17', '23', '33']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'Search'},{'id': '22', 'type': 'argument_list', 'children': []},{'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': 's'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'recent'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30', '31', '32']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'pages'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '33', 'type': 'return_statement', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 's'}
def recent(category=None, pages=1, sort=None, order=None): s = Search() s.recent(category, pages, sort, order) return s
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'pick_action_todo'},{'id': '3', 'type': 'parameters', 'children': []},{'id': '4', 'type': 'block', 'children': ['5', '67']},{'id': '5', 'type': 'for_statement', 'children': ['6', '9', '13']},{'id': '6', 'type': 'pattern_list', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'ndx'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'todo'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'things_to_do'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'if_statement', 'children': ['15', '21']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'roll_dice'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'subscript', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'todo'},{'id': '20', 'type': 'string', 'children': [], 'value': '"chance"'},{'id': '21', 'type': 'block', 'children': ['22', '33', '50']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'cur_act'},{'id': '25', 'type': 'subscript', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'actions'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'get_action_by_name'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'subscript', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'todo'},{'id': '32', 'type': 'string', 'children': [], 'value': '"name"'},{'id': '33', 'type': 'if_statement', 'children': ['34', '47']},{'id': '34', 'type': 'boolean_operator', 'children': ['35', '40'], 'value': 'and'},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '39'], 'value': '=='},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'todo'},{'id': '38', 'type': 'string', 'children': [], 'value': '"WHERE_COL"'},{'id': '39', 'type': 'string', 'children': [], 'value': '"energy"'},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '44'], 'value': '>'},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'my_char'},{'id': '43', 'type': 'string', 'children': [], 'value': '"energy"'},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'todo'},{'id': '46', 'type': 'string', 'children': [], 'value': '"WHERE_VAL"'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'return_statement', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'cur_act'},{'id': '50', 'type': 'if_statement', 'children': ['51', '64']},{'id': '51', 'type': 'boolean_operator', 'children': ['52', '57'], 'value': 'and'},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '56'], 'value': '=='},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'todo'},{'id': '55', 'type': 'string', 'children': [], 'value': '"WHERE_COL"'},{'id': '56', 'type': 'string', 'children': [], 'value': '"gold"'},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '61'], 'value': '>'},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'my_char'},{'id': '60', 'type': 'string', 'children': [], 'value': '"gold"'},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'todo'},{'id': '63', 'type': 'string', 'children': [], 'value': '"WHERE_VAL"'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'return_statement', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'cur_act'},{'id': '67', 'type': 'return_statement', 'children': ['68']},{'id': '68', 'type': 'subscript', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'actions'},{'id': '70', 'type': 'integer', 'children': [], 'value': '3'}
def pick_action_todo(): for ndx, todo in enumerate(things_to_do): if roll_dice(todo["chance"]): cur_act = actions[get_action_by_name(todo["name"])] if todo["WHERE_COL"] == "energy" and my_char["energy"] > todo["WHERE_VAL"]: return cur_act if todo["WHERE_COL"] == "gold" and my_char["gold"] > todo["WHERE_VAL"]: return cur_act return actions[3]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'select'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'soup'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'selector'},{'id': '6', 'type': 'block', 'children': ['7', '15', '20', '266']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'selector'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '14', 'type': 'argument_list', 'children': []},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'current_context'},{'id': '18', 'type': 'list', 'children': ['19'], 'value': '[soup]'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'soup'},{'id': '20', 'type': 'for_statement', 'children': ['21', '22', '23']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '23', 'type': 'block', 'children': ['24', '33', '99', '109', '124', '130', '135', '136', '201', '231', '242', '246', '262']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'attribselect_re'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '33', 'type': 'if_statement', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '35', 'type': 'block', 'children': ['36', '48', '56', '65', '69', '94', '98']},{'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': 'tag'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'attribute'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '47', 'type': 'argument_list', 'children': []},{'id': '48', 'type': 'if_statement', 'children': ['49', '51']},{'id': '49', 'type': 'not_operator', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '55', 'type': 'True', 'children': []},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'checker'},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'attribute_checker'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63', '64']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'attribute'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '68', 'type': 'list', 'children': [], 'value': '[]'},{'id': '69', 'type': 'for_statement', 'children': ['70', '71', '72']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'current_context'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'list_comprehension', 'children': ['80', '81', '89']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '81', 'type': 'for_in_clause', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'findAll'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '89', 'type': 'if_clause', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'checker'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'current_context'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '98', 'type': 'continue_statement', 'children': []},{'id': '99', 'type': 'if_statement', 'children': ['100', '101', '104']},{'id': '100', 'type': 'string', 'children': [], 'value': "'\n tag, id = token.split('"},{'id': '101', 'type': 'ERROR', 'children': ['102']},{'id': '102', 'type': 'not_operator', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'tag'},{'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': 'tag'},{'id': '108', 'type': 'True', 'children': []},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '112', 'type': 'call', 'children': ['113', '118']},{'id': '113', 'type': 'attribute', 'children': ['114', '117']},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'current_context'},{'id': '116', 'type': 'integer', 'children': [], 'value': '0'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '118', 'type': 'argument_list', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '120', 'type': 'dictionary', 'children': ['121']},{'id': '121', 'type': 'pair', 'children': ['122', '123']},{'id': '122', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '124', 'type': 'if_statement', 'children': ['125', '127']},{'id': '125', 'type': 'not_operator', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'return_statement', 'children': ['129']},{'id': '129', 'type': 'list', 'children': [], 'value': '[]'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'current_context'},{'id': '133', 'type': 'list', 'children': ['134'], 'value': '[el]'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '135', 'type': 'continue_statement', 'children': []},{'id': '136', 'type': 'if_statement', 'children': ['137', '140']},{'id': '137', 'type': 'comparison_operator', 'children': ['138', '139'], 'value': 'in'},{'id': '138', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '140', 'type': 'block', 'children': ['141', '153', '161', '165', '196', '200']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '146']},{'id': '143', 'type': 'pattern_list', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'klass'},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '150', 'type': 'argument_list', 'children': ['151', '152']},{'id': '151', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '152', 'type': 'integer', 'children': [], 'value': '1'},{'id': '153', 'type': 'if_statement', 'children': ['154', '156']},{'id': '154', 'type': 'not_operator', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'tag'},{'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': 'tag'},{'id': '160', 'type': 'True', 'children': []},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '164', 'type': 'list', 'children': [], 'value': '[]'},{'id': '165', 'type': 'for_statement', 'children': ['166', '167', '168']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'current_context'},{'id': '168', 'type': 'block', 'children': ['169']},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'findAll'},{'id': '179', 'type': 'argument_list', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '181', 'type': 'dictionary', 'children': ['182']},{'id': '182', 'type': 'pair', 'children': ['183', '184']},{'id': '183', 'type': 'string', 'children': [], 'value': "'class'"},{'id': '184', 'type': 'lambda', 'children': ['185', '187']},{'id': '185', 'type': 'lambda_parameters', 'children': ['186']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '187', 'type': 'boolean_operator', 'children': ['188', '189'], 'value': 'and'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '189', 'type': 'comparison_operator', 'children': ['190', '191'], 'value': 'in'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'klass'},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '195', 'type': 'argument_list', 'children': []},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'current_context'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '200', 'type': 'continue_statement', 'children': []},{'id': '201', 'type': 'if_statement', 'children': ['202', '205']},{'id': '202', 'type': 'comparison_operator', 'children': ['203', '204'], 'value': '=='},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '204', 'type': 'string', 'children': [], 'value': "'*'"},{'id': '205', 'type': 'block', 'children': ['206', '210', '226', '230']},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '209', 'type': 'list', 'children': [], 'value': '[]'},{'id': '210', 'type': 'for_statement', 'children': ['211', '212', '213']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'current_context'},{'id': '213', 'type': 'block', 'children': ['214']},{'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': 'found'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'findAll'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'True', 'children': []},{'id': '226', 'type': 'expression_statement', 'children': ['227']},{'id': '227', 'type': 'assignment', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'current_context'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '230', 'type': 'continue_statement', 'children': []},{'id': '231', 'type': 'if_statement', 'children': ['232', '239']},{'id': '232', 'type': 'not_operator', 'children': ['233']},{'id': '233', 'type': 'call', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'tag_re'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '237', 'type': 'argument_list', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '239', 'type': 'block', 'children': ['240']},{'id': '240', 'type': 'return_statement', 'children': ['241']},{'id': '241', 'type': 'list', 'children': [], 'value': '[]'},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'assignment', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '245', 'type': 'list', 'children': [], 'value': '[]'},{'id': '246', 'type': 'for_statement', 'children': ['247', '248', '249']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'current_context'},{'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': 'found'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'call', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'findAll'},{'id': '260', 'type': 'argument_list', 'children': ['261']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'assignment', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'current_context'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '266', 'type': 'return_statement', 'children': ['267']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'current_context'}
def select(soup, selector): tokens = selector.split() current_context = [soup] for token in tokens: m = attribselect_re.match(token) if m: tag, attribute, operator, value = m.groups() if not tag: tag = True checker = attribute_checker(operator, attribute, value) found = [] for context in current_context: found.extend([el for el in context.findAll(tag) if checker(el)]) current_context = found continue if ' tag, id = token.split(' if not tag: tag = True el = current_context[0].find(tag, {'id': id}) if not el: return [] current_context = [el] continue if '.' in token: tag, klass = token.split('.', 1) if not tag: tag = True found = [] for context in current_context: found.extend( context.findAll(tag, {'class': lambda attr: attr and klass in attr.split()} ) ) current_context = found continue if token == '*': found = [] for context in current_context: found.extend(context.findAll(True)) current_context = found continue if not tag_re.match(token): return [] found = [] for context in current_context: found.extend(context.findAll(token)) current_context = found return current_context
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'try_'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'except_'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'else_'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'finally_'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '20', '36', '47']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'ensure_callable'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '20', 'type': 'if_statement', 'children': ['21', '28']},{'id': '21', 'type': 'not_operator', 'children': ['22']},{'id': '22', 'type': '()', 'children': ['23']},{'id': '23', 'type': 'boolean_operator', 'children': ['24', '27'], 'value': 'or'},{'id': '24', 'type': 'boolean_operator', 'children': ['25', '26'], 'value': 'or'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'except_'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'else_'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'finally_'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'raise_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'concatenated_string', 'children': ['34', '35']},{'id': '34', 'type': 'string', 'children': [], 'value': '"at least one of `except_`, `else_` or `finally_` "'},{'id': '35', 'type': 'string', 'children': [], 'value': '"functions must be provided"'},{'id': '36', 'type': 'if_statement', 'children': ['37', '41']},{'id': '37', 'type': 'boolean_operator', 'children': ['38', '39'], 'value': 'and'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'else_'},{'id': '39', 'type': 'not_operator', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'except_'},{'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': 'TypeError'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'string', 'children': [], 'value': '"`else_` can only be provided along with `except_`"'},{'id': '47', 'type': 'if_statement', 'children': ['48', '49', '228']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'except_'},{'id': '49', 'type': 'block', 'children': ['50', '89', '126']},{'id': '50', 'type': 'if_statement', 'children': ['51', '55', '63']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'callable'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'except_'},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'except_'},{'id': '59', 'type': 'list', 'children': ['60'], 'value': '[(Exception, except_)]'},{'id': '60', 'type': 'tuple', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'except_'},{'id': '63', 'type': 'else_clause', 'children': ['64']},{'id': '64', 'type': 'block', 'children': ['65', '70']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'ensure_iterable'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'except_'},{'id': '70', 'type': 'if_statement', 'children': ['71', '75']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'is_mapping'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'except_'},{'id': '75', 'type': 'block', 'children': ['76', '81']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'ensure_ordered_mapping'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'except_'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'except_'},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'except_'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '88', 'type': 'argument_list', 'children': []},{'id': '89', 'type': 'function_definition', 'children': ['90', '91', '92']},{'id': '90', 'type': 'function_name', 'children': [], 'value': 'handle_exception'},{'id': '91', 'type': 'parameters', 'children': []},{'id': '92', 'type': 'block', 'children': ['93', '107', '125']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '98']},{'id': '95', 'type': 'pattern_list', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'exc_type'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'exc_object'},{'id': '98', 'type': 'subscript', 'children': ['99', '104']},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'exc_info'},{'id': '103', 'type': 'argument_list', 'children': []},{'id': '104', 'type': 'slice', 'children': ['105', '106']},{'id': '105', 'type': 'colon', 'children': []},{'id': '106', 'type': 'integer', 'children': [], 'value': '2'},{'id': '107', 'type': 'for_statement', 'children': ['108', '111', '112']},{'id': '108', 'type': 'pattern_list', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'handler'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'except_'},{'id': '112', 'type': 'block', 'children': ['113']},{'id': '113', 'type': 'if_statement', 'children': ['114', '119']},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'issubclass'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'exc_type'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 't'},{'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': 'handler'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'exc_object'},{'id': '125', 'type': 'raise_statement', 'children': []},{'id': '126', 'type': 'if_statement', 'children': ['127', '128', '186']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'else_'},{'id': '128', 'type': 'block', 'children': ['129', '134']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'ensure_callable'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'else_'},{'id': '134', 'type': 'if_statement', 'children': ['135', '136', '166']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'finally_'},{'id': '136', 'type': 'block', 'children': ['137', '142']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'ensure_callable'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'finally_'},{'id': '142', 'type': 'try_statement', 'children': ['143', '148', '154', '160']},{'id': '143', 'type': 'block', 'children': ['144']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '147', 'type': 'argument_list', 'children': []},{'id': '148', 'type': 'except_clause', 'children': ['149']},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'return_statement', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'handle_exception'},{'id': '153', 'type': 'argument_list', 'children': []},{'id': '154', 'type': 'else_clause', 'children': ['155']},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'return_statement', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'else_'},{'id': '159', 'type': 'argument_list', 'children': []},{'id': '160', 'type': 'finally_clause', 'children': ['161']},{'id': '161', 'type': 'block', 'children': ['162']},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'finally_'},{'id': '165', 'type': 'argument_list', 'children': []},{'id': '166', 'type': 'else_clause', 'children': ['167']},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'try_statement', 'children': ['169', '174', '180']},{'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': 'block'},{'id': '173', 'type': 'argument_list', 'children': []},{'id': '174', 'type': 'except_clause', 'children': ['175']},{'id': '175', 'type': 'block', 'children': ['176']},{'id': '176', 'type': 'return_statement', 'children': ['177']},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'handle_exception'},{'id': '179', 'type': 'argument_list', 'children': []},{'id': '180', 'type': 'else_clause', 'children': ['181']},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'return_statement', 'children': ['183']},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'else_'},{'id': '185', 'type': 'argument_list', 'children': []},{'id': '186', 'type': 'else_clause', 'children': ['187']},{'id': '187', 'type': 'block', 'children': ['188']},{'id': '188', 'type': 'if_statement', 'children': ['189', '190', '214']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'finally_'},{'id': '190', 'type': 'block', 'children': ['191', '196']},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'call', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'ensure_callable'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'finally_'},{'id': '196', 'type': 'try_statement', 'children': ['197', '202', '208']},{'id': '197', 'type': 'block', 'children': ['198']},{'id': '198', 'type': 'return_statement', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '201', 'type': 'argument_list', 'children': []},{'id': '202', 'type': 'except_clause', 'children': ['203']},{'id': '203', 'type': 'block', 'children': ['204']},{'id': '204', 'type': 'return_statement', 'children': ['205']},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'handle_exception'},{'id': '207', 'type': 'argument_list', 'children': []},{'id': '208', 'type': 'finally_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': 'finally_'},{'id': '213', 'type': 'argument_list', 'children': []},{'id': '214', 'type': 'else_clause', 'children': ['215']},{'id': '215', 'type': 'block', 'children': ['216']},{'id': '216', 'type': 'try_statement', 'children': ['217', '222']},{'id': '217', 'type': 'block', 'children': ['218']},{'id': '218', 'type': 'return_statement', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '221', 'type': 'argument_list', 'children': []},{'id': '222', 'type': 'except_clause', 'children': ['223']},{'id': '223', 'type': 'block', 'children': ['224']},{'id': '224', 'type': 'return_statement', 'children': ['225']},{'id': '225', 'type': 'call', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'handle_exception'},{'id': '227', 'type': 'argument_list', 'children': []},{'id': '228', 'type': 'elif_clause', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'finally_'},{'id': '230', 'type': 'block', 'children': ['231', '236']},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'ensure_callable'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'finally_'},{'id': '236', 'type': 'try_statement', 'children': ['237', '242']},{'id': '237', 'type': 'block', 'children': ['238']},{'id': '238', 'type': 'return_statement', 'children': ['239']},{'id': '239', 'type': 'call', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '241', 'type': 'argument_list', 'children': []},{'id': '242', 'type': 'finally_clause', 'children': ['243']},{'id': '243', 'type': 'block', 'children': ['244']},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'call', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'finally_'},{'id': '247', 'type': 'argument_list', 'children': []}
def try_(block, except_=None, else_=None, finally_=None): ensure_callable(block) if not (except_ or else_ or finally_): raise TypeError("at least one of `except_`, `else_` or `finally_` " "functions must be provided") if else_ and not except_: raise TypeError("`else_` can only be provided along with `except_`") if except_: if callable(except_): except_ = [(Exception, except_)] else: ensure_iterable(except_) if is_mapping(except_): ensure_ordered_mapping(except_) except_ = except_.items() def handle_exception(): exc_type, exc_object = sys.exc_info()[:2] for t, handler in except_: if issubclass(exc_type, t): return handler(exc_object) raise if else_: ensure_callable(else_) if finally_: ensure_callable(finally_) try: block() except: return handle_exception() else: return else_() finally: finally_() else: try: block() except: return handle_exception() else: return else_() else: if finally_: ensure_callable(finally_) try: return block() except: return handle_exception() finally: finally_() else: try: return block() except: return handle_exception() elif finally_: ensure_callable(finally_) try: return block() finally: finally_()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'replace_u_end_day'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'month'},{'id': '7', 'type': 'block', 'children': ['8', '17', '24', '36', '58', '75', '109', '128', '152']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'lstrip'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'month'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'month'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'lstrip'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '36', 'type': 'if_statement', 'children': ['37', '44']},{'id': '37', 'type': 'boolean_operator', 'children': ['38', '41'], 'value': 'or'},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': '=='},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '40', 'type': 'string', 'children': [], 'value': "'uu'"},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': '=='},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '43', 'type': 'string', 'children': [], 'value': "'3u'"},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'return_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'subscript', 'children': ['50', '57']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'calendar'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'monthrange'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'month'},{'id': '57', 'type': 'integer', 'children': [], 'value': '1'},{'id': '58', 'type': 'if_statement', 'children': ['59', '66']},{'id': '59', 'type': 'boolean_operator', 'children': ['60', '63'], 'value': 'or'},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': '=='},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '62', 'type': 'string', 'children': [], 'value': "'0u'"},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': '=='},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '65', 'type': 'string', 'children': [], 'value': "'1u'"},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'return_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74']},{'id': '73', 'type': 'string', 'children': [], 'value': "'u'"},{'id': '74', 'type': 'string', 'children': [], 'value': "'9'"},{'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': '=='},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '79', 'type': 'string', 'children': [], 'value': "'2u'"},{'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': '=='},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '82', 'type': 'string', 'children': [], 'value': "'u9'"},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'if_statement', 'children': ['85', '95', '98', '105']},{'id': '85', 'type': 'boolean_operator', 'children': ['86', '89'], 'value': 'or'},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': '!='},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'month'},{'id': '88', 'type': 'string', 'children': [], 'value': "'02'"},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'calendar'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'isleap'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'return_statement', 'children': ['97']},{'id': '97', 'type': 'string', 'children': [], 'value': "'29'"},{'id': '98', 'type': 'elif_clause', 'children': ['99', '102']},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': '=='},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '101', 'type': 'string', 'children': [], 'value': "'2u'"},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'return_statement', 'children': ['104']},{'id': '104', 'type': 'string', 'children': [], 'value': "'28'"},{'id': '105', 'type': 'else_clause', 'children': ['106']},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'return_statement', 'children': ['108']},{'id': '108', 'type': 'string', 'children': [], 'value': "'19'"},{'id': '109', 'type': 'if_statement', 'children': ['110', '119']},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '112', '118'], 'value': '<'},{'id': '111', 'type': 'integer', 'children': [], 'value': '1'},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '117', 'type': 'integer', 'children': [], 'value': '1'},{'id': '118', 'type': 'integer', 'children': [], 'value': '9'},{'id': '119', 'type': 'block', 'children': ['120']},{'id': '120', 'type': 'return_statement', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '125', 'type': 'argument_list', 'children': ['126', '127']},{'id': '126', 'type': 'string', 'children': [], 'value': "'u'"},{'id': '127', 'type': 'string', 'children': [], 'value': "'2'"},{'id': '128', 'type': 'if_statement', 'children': ['129', '132']},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': '=='},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '131', 'type': 'string', 'children': [], 'value': "'u1'"},{'id': '132', 'type': 'block', 'children': ['133']},{'id': '133', 'type': 'if_statement', 'children': ['134', '145', '148']},{'id': '134', 'type': 'comparison_operator', 'children': ['135', '144'], 'value': '=='},{'id': '135', 'type': 'subscript', 'children': ['136', '143']},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'calendar'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'monthrange'},{'id': '140', 'type': 'argument_list', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'month'},{'id': '143', 'type': 'integer', 'children': [], 'value': '1'},{'id': '144', 'type': 'integer', 'children': [], 'value': '31'},{'id': '145', 'type': 'block', 'children': ['146']},{'id': '146', 'type': 'return_statement', 'children': ['147']},{'id': '147', 'type': 'string', 'children': [], 'value': "'31'"},{'id': '148', 'type': 'else_clause', 'children': ['149']},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'return_statement', 'children': ['151']},{'id': '151', 'type': 'string', 'children': [], 'value': "'21'"},{'id': '152', 'type': 'if_statement', 'children': ['153', '156', '172']},{'id': '153', 'type': 'comparison_operator', 'children': ['154', '155'], 'value': '=='},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '155', 'type': 'string', 'children': [], 'value': "'u0'"},{'id': '156', 'type': 'block', 'children': ['157']},{'id': '157', 'type': 'if_statement', 'children': ['158', '169']},{'id': '158', 'type': 'comparison_operator', 'children': ['159', '168'], 'value': '>='},{'id': '159', 'type': 'subscript', 'children': ['160', '167']},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'calendar'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'monthrange'},{'id': '164', 'type': 'argument_list', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'month'},{'id': '167', 'type': 'integer', 'children': [], 'value': '1'},{'id': '168', 'type': 'integer', 'children': [], 'value': '30'},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'return_statement', 'children': ['171']},{'id': '171', 'type': 'string', 'children': [], 'value': "'30'"},{'id': '172', 'type': 'else_clause', 'children': ['173']},{'id': '173', 'type': 'block', 'children': ['174']},{'id': '174', 'type': 'return_statement', 'children': ['175']},{'id': '175', 'type': 'string', 'children': [], 'value': "'20'"}
def replace_u_end_day(day, year, month): day = day.lstrip('-') year = int(year) month = int(month.lstrip('-')) if day == 'uu' or day == '3u': return str(calendar.monthrange(year, month)[1]) if day == '0u' or day == '1u': return day.replace('u', '9') if day == '2u' or day == 'u9': if month != '02' or calendar.isleap(year): return '29' elif day == '2u': return '28' else: return '19' if 1 < int(day[1]) < 9: return day.replace('u', '2') if day == 'u1': if calendar.monthrange(year, month)[1] == 31: return '31' else: return '21' if day == 'u0': if calendar.monthrange(year, month)[1] >= 30: return '30' else: return '20'
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'zero_year_special_case'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'if_statement', 'children': ['10', '17', '240', '251']},{'id': '10', 'type': 'boolean_operator', 'children': ['11', '14'], 'value': 'and'},{'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': '=='},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '13', 'type': 'string', 'children': [], 'value': "'pos'"},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': '=='},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '16', 'type': 'string', 'children': [], 'value': "'pos'"},{'id': '17', 'type': 'block', 'children': ['18', '36', '54']},{'id': '18', 'type': 'if_statement', 'children': ['19', '33']},{'id': '19', 'type': 'boolean_operator', 'children': ['20', '26'], 'value': 'and'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'string', 'children': [], 'value': "'0000'"},{'id': '26', 'type': 'not_operator', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'string', 'children': [], 'value': "'0000'"},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'return_statement', 'children': ['35']},{'id': '35', 'type': 'True', 'children': []},{'id': '36', 'type': 'if_statement', 'children': ['37', '51']},{'id': '37', 'type': 'boolean_operator', 'children': ['38', '45'], 'value': 'and'},{'id': '38', 'type': 'not_operator', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'string', 'children': [], 'value': "'0000'"},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'string', 'children': [], 'value': "'0000'"},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'return_statement', 'children': ['53']},{'id': '53', 'type': 'False', 'children': []},{'id': '54', 'type': 'if_statement', 'children': ['55', '68']},{'id': '55', 'type': 'boolean_operator', 'children': ['56', '62'], 'value': 'and'},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'string', 'children': [], 'value': "'0000'"},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'string', 'children': [], 'value': "'0000'"},{'id': '68', 'type': 'block', 'children': ['69', '141', '213', '220']},{'id': '69', 'type': 'if_statement', 'children': ['70', '76', '85', '109']},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '75'], 'value': '=='},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '75', 'type': 'integer', 'children': [], 'value': '4'},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '82']},{'id': '79', 'type': 'pattern_list', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'fm'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '82', 'type': 'expression_list', 'children': ['83', '84']},{'id': '83', 'type': 'integer', 'children': [], 'value': '1'},{'id': '84', 'type': 'integer', 'children': [], 'value': '1'},{'id': '85', 'type': 'elif_clause', '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': 'from_date'},{'id': '91', 'type': 'integer', 'children': [], 'value': '7'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '98']},{'id': '95', 'type': 'pattern_list', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'fm'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '98', 'type': 'expression_list', 'children': ['99', '108']},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '104', 'type': 'slice', 'children': ['105', '106', '107']},{'id': '105', 'type': 'integer', 'children': [], 'value': '5'},{'id': '106', 'type': 'colon', 'children': []},{'id': '107', 'type': 'integer', 'children': [], 'value': '7'},{'id': '108', 'type': 'integer', 'children': [], 'value': '1'},{'id': '109', 'type': 'elif_clause', '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': 'from_date'},{'id': '115', 'type': 'integer', 'children': [], 'value': '10'},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '122']},{'id': '119', 'type': 'pattern_list', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'fm'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '122', 'type': 'expression_list', 'children': ['123', '132']},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'subscript', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '128', 'type': 'slice', 'children': ['129', '130', '131']},{'id': '129', 'type': 'integer', 'children': [], 'value': '5'},{'id': '130', 'type': 'colon', 'children': []},{'id': '131', 'type': 'integer', 'children': [], 'value': '7'},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '137', 'type': 'slice', 'children': ['138', '139', '140']},{'id': '138', 'type': 'integer', 'children': [], 'value': '8'},{'id': '139', 'type': 'colon', 'children': []},{'id': '140', 'type': 'integer', 'children': [], 'value': '10'},{'id': '141', 'type': 'if_statement', 'children': ['142', '148', '157', '181']},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '147'], 'value': '=='},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '147', 'type': 'integer', 'children': [], 'value': '4'},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '154']},{'id': '151', 'type': 'pattern_list', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'tm'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'td'},{'id': '154', 'type': 'expression_list', 'children': ['155', '156']},{'id': '155', 'type': 'integer', 'children': [], 'value': '1'},{'id': '156', 'type': 'integer', 'children': [], 'value': '1'},{'id': '157', 'type': 'elif_clause', 'children': ['158', '164']},{'id': '158', 'type': 'comparison_operator', 'children': ['159', '163'], 'value': '=='},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '163', 'type': 'integer', 'children': [], 'value': '7'},{'id': '164', 'type': 'block', 'children': ['165']},{'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': 'tm'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'td'},{'id': '170', 'type': 'expression_list', 'children': ['171', '180']},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'subscript', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '176', 'type': 'slice', 'children': ['177', '178', '179']},{'id': '177', 'type': 'integer', 'children': [], 'value': '5'},{'id': '178', 'type': 'colon', 'children': []},{'id': '179', 'type': 'integer', 'children': [], 'value': '7'},{'id': '180', 'type': 'integer', 'children': [], 'value': '1'},{'id': '181', 'type': 'elif_clause', 'children': ['182', '188']},{'id': '182', 'type': 'comparison_operator', 'children': ['183', '187'], 'value': '=='},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '187', 'type': 'integer', 'children': [], 'value': '10'},{'id': '188', 'type': 'block', 'children': ['189']},{'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': 'tm'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'td'},{'id': '194', 'type': 'expression_list', 'children': ['195', '204']},{'id': '195', 'type': 'call', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'subscript', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '200', 'type': 'slice', 'children': ['201', '202', '203']},{'id': '201', 'type': 'integer', 'children': [], 'value': '5'},{'id': '202', 'type': 'colon', 'children': []},{'id': '203', 'type': 'integer', 'children': [], 'value': '7'},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'subscript', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '209', 'type': 'slice', 'children': ['210', '211', '212']},{'id': '210', 'type': 'integer', 'children': [], 'value': '8'},{'id': '211', 'type': 'colon', 'children': []},{'id': '212', 'type': 'integer', 'children': [], 'value': '10'},{'id': '213', 'type': 'if_statement', 'children': ['214', '217']},{'id': '214', 'type': 'comparison_operator', 'children': ['215', '216'], 'value': '=='},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '217', 'type': 'block', 'children': ['218']},{'id': '218', 'type': 'return_statement', 'children': ['219']},{'id': '219', 'type': 'True', 'children': []},{'id': '220', 'type': 'if_statement', 'children': ['221', '224', '236']},{'id': '221', 'type': 'comparison_operator', 'children': ['222', '223'], 'value': '<='},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'fm'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'tm'},{'id': '224', 'type': 'block', 'children': ['225']},{'id': '225', 'type': 'if_statement', 'children': ['226', '229', '232']},{'id': '226', 'type': 'comparison_operator', 'children': ['227', '228'], 'value': '<='},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'td'},{'id': '229', 'type': 'block', 'children': ['230']},{'id': '230', 'type': 'return_statement', 'children': ['231']},{'id': '231', 'type': 'True', 'children': []},{'id': '232', 'type': 'else_clause', 'children': ['233']},{'id': '233', 'type': 'block', 'children': ['234']},{'id': '234', 'type': 'return_statement', 'children': ['235']},{'id': '235', 'type': 'False', 'children': []},{'id': '236', 'type': 'else_clause', 'children': ['237']},{'id': '237', 'type': 'block', 'children': ['238']},{'id': '238', 'type': 'return_statement', 'children': ['239']},{'id': '239', 'type': 'False', 'children': []},{'id': '240', 'type': 'elif_clause', 'children': ['241', '248']},{'id': '241', 'type': 'boolean_operator', 'children': ['242', '245'], 'value': 'and'},{'id': '242', 'type': 'comparison_operator', 'children': ['243', '244'], 'value': '=='},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '244', 'type': 'string', 'children': [], 'value': "'neg'"},{'id': '245', 'type': 'comparison_operator', 'children': ['246', '247'], 'value': '=='},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '247', 'type': 'string', 'children': [], 'value': "'neg'"},{'id': '248', 'type': 'block', 'children': ['249']},{'id': '249', 'type': 'return_statement', 'children': ['250']},{'id': '250', 'type': 'False', 'children': []},{'id': '251', 'type': 'elif_clause', 'children': ['252', '259']},{'id': '252', 'type': 'boolean_operator', 'children': ['253', '256'], 'value': 'and'},{'id': '253', 'type': 'comparison_operator', 'children': ['254', '255'], 'value': '=='},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '255', 'type': 'string', 'children': [], 'value': "'neg'"},{'id': '256', 'type': 'comparison_operator', 'children': ['257', '258'], 'value': '=='},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '258', 'type': 'string', 'children': [], 'value': "'pos'"},{'id': '259', 'type': 'block', 'children': ['260']},{'id': '260', 'type': 'if_statement', 'children': ['261', '267', '270']},{'id': '261', 'type': 'call', 'children': ['262', '265']},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '265', 'type': 'argument_list', 'children': ['266']},{'id': '266', 'type': 'string', 'children': [], 'value': '"0000"'},{'id': '267', 'type': 'block', 'children': ['268']},{'id': '268', 'type': 'return_statement', 'children': ['269']},{'id': '269', 'type': 'False', 'children': []},{'id': '270', 'type': 'else_clause', 'children': ['271']},{'id': '271', 'type': 'block', 'children': ['272']},{'id': '272', 'type': 'return_statement', 'children': ['273']},{'id': '273', 'type': 'True', 'children': []}
def zero_year_special_case(from_date, to_date, start, end): if start == 'pos' and end == 'pos': if from_date.startswith('0000') and not to_date.startswith('0000'): return True if not from_date.startswith('0000') and to_date.startswith('0000'): return False if from_date.startswith('0000') and to_date.startswith('0000'): if len(from_date) == 4: fm, fd = 1, 1 elif len(from_date) == 7: fm, fd = int(from_date[5:7]), 1 elif len(from_date) == 10: fm, fd = int(from_date[5:7]), int(from_date[8:10]) if len(to_date) == 4: tm, td = 1, 1 elif len(to_date) == 7: tm, td = int(to_date[5:7]), 1 elif len(to_date) == 10: tm, td = int(to_date[5:7]), int(to_date[8:10]) if from_date == to_date: return True if fm <= tm: if fd <= td: return True else: return False else: return False elif start == 'neg' and end == 'neg': return False elif start == 'neg' and end == 'pos': if from_date.startswith("0000"): return False else: return True
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'is_valid_interval'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'edtf_candidate'},{'id': '5', 'type': 'block', 'children': ['6', '10', '14', '22']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '19']},{'id': '16', 'type': 'pattern_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '19', 'type': 'expression_list', 'children': ['20', '21']},{'id': '20', 'type': 'string', 'children': [], 'value': "'pos'"},{'id': '21', 'type': 'string', 'children': [], 'value': "'pos'"},{'id': '22', 'type': 'if_statement', 'children': ['23', '31', '427']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '30'], 'value': '=='},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'edtf_candidate'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '30', 'type': 'integer', 'children': [], 'value': '1'},{'id': '31', 'type': 'block', 'children': ['32', '40', '51', '60', '86', '112', '123', '154', '180', '206', '232', '258', '305', '350']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'edtf_candidate'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'replace_all'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'edtf_candidate'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'interval_replacements'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'edtf_candidate'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49', '50']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'U_PATTERN'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'replace_u'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'edtf_candidate'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'edtf_candidate'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '60', 'type': 'if_statement', 'children': ['61', '69']},{'id': '61', 'type': 'call', 'children': ['62', '67']},{'id': '62', 'type': 'attribute', 'children': ['63', '66']},{'id': '63', 'type': 'subscript', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '65', 'type': 'integer', 'children': [], 'value': '0'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '69', 'type': 'block', 'children': ['70', '74']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '73', 'type': 'string', 'children': [], 'value': "'neg'"},{'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': 'parts'},{'id': '78', 'type': 'integer', 'children': [], 'value': '0'},{'id': '79', 'type': 'subscript', 'children': ['80', '83']},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '82', 'type': 'integer', 'children': [], 'value': '0'},{'id': '83', 'type': 'slice', 'children': ['84', '85']},{'id': '84', 'type': 'integer', 'children': [], 'value': '1'},{'id': '85', 'type': 'colon', 'children': []},{'id': '86', 'type': 'if_statement', 'children': ['87', '95']},{'id': '87', 'type': 'call', 'children': ['88', '93']},{'id': '88', 'type': 'attribute', 'children': ['89', '92']},{'id': '89', 'type': 'subscript', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '91', 'type': 'integer', 'children': [], 'value': '1'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '95', 'type': 'block', 'children': ['96', '100']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '99', 'type': 'string', 'children': [], 'value': "'neg'"},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '105']},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '104', 'type': 'integer', 'children': [], 'value': '1'},{'id': '105', 'type': 'subscript', 'children': ['106', '109']},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '108', 'type': 'integer', 'children': [], 'value': '1'},{'id': '109', 'type': 'slice', 'children': ['110', '111']},{'id': '110', 'type': 'integer', 'children': [], 'value': '1'},{'id': '111', 'type': 'colon', 'children': []},{'id': '112', 'type': 'if_statement', 'children': ['113', '120']},{'id': '113', 'type': 'boolean_operator', 'children': ['114', '117'], 'value': 'and'},{'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': '=='},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '116', 'type': 'string', 'children': [], 'value': "'pos'"},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '119'], 'value': '=='},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '119', 'type': 'string', 'children': [], 'value': "'neg'"},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'return_statement', 'children': ['122']},{'id': '122', 'type': 'False', 'children': []},{'id': '123', 'type': 'if_statement', 'children': ['124', '141']},{'id': '124', 'type': 'boolean_operator', 'children': ['125', '133'], 'value': 'or'},{'id': '125', 'type': 'call', 'children': ['126', '131']},{'id': '126', 'type': 'attribute', 'children': ['127', '130']},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '129', 'type': 'integer', 'children': [], 'value': '0'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'string', 'children': [], 'value': '"0000"'},{'id': '133', 'type': 'call', 'children': ['134', '139']},{'id': '134', 'type': 'attribute', 'children': ['135', '138']},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '137', 'type': 'integer', 'children': [], 'value': '1'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'string', 'children': [], 'value': '"0000"'},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'return_statement', 'children': ['143']},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'zero_year_special_case'},{'id': '145', 'type': 'argument_list', 'children': ['146', '149', '152', '153']},{'id': '146', 'type': 'subscript', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '148', 'type': 'integer', 'children': [], 'value': '0'},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '151', 'type': 'integer', 'children': [], 'value': '1'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '154', 'type': 'if_statement', 'children': ['155', '165']},{'id': '155', 'type': 'comparison_operator', 'children': ['156', '164'], 'value': '=='},{'id': '156', 'type': 'call', 'children': ['157', '162']},{'id': '157', 'type': 'attribute', 'children': ['158', '161']},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '160', 'type': 'integer', 'children': [], 'value': '0'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '164', 'type': 'integer', 'children': [], 'value': '2'},{'id': '165', 'type': 'block', 'children': ['166']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'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': 'datetime'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'strptime'},{'id': '175', 'type': 'argument_list', 'children': ['176', '179']},{'id': '176', 'type': 'subscript', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '178', 'type': 'integer', 'children': [], 'value': '0'},{'id': '179', 'type': 'string', 'children': [], 'value': '"%Y-%m-%d"'},{'id': '180', 'type': 'if_statement', 'children': ['181', '191']},{'id': '181', 'type': 'comparison_operator', 'children': ['182', '190'], 'value': '=='},{'id': '182', 'type': 'call', 'children': ['183', '188']},{'id': '183', 'type': 'attribute', 'children': ['184', '187']},{'id': '184', 'type': 'subscript', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '186', 'type': 'integer', 'children': [], 'value': '1'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '190', 'type': 'integer', 'children': [], 'value': '2'},{'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': 'to_date'},{'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': 'datetime'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'strptime'},{'id': '201', 'type': 'argument_list', 'children': ['202', '205']},{'id': '202', 'type': 'subscript', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '204', 'type': 'integer', 'children': [], 'value': '1'},{'id': '205', 'type': 'string', 'children': [], 'value': '"%Y-%m-%d"'},{'id': '206', 'type': 'if_statement', 'children': ['207', '217']},{'id': '207', 'type': 'comparison_operator', 'children': ['208', '216'], 'value': '=='},{'id': '208', 'type': 'call', 'children': ['209', '214']},{'id': '209', 'type': 'attribute', 'children': ['210', '213']},{'id': '210', 'type': 'subscript', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '212', 'type': 'integer', 'children': [], 'value': '0'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '216', 'type': 'integer', 'children': [], 'value': '1'},{'id': '217', 'type': 'block', 'children': ['218']},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'assignment', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '221', 'type': 'call', 'children': ['222', '227']},{'id': '222', 'type': 'attribute', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'strptime'},{'id': '227', 'type': 'argument_list', 'children': ['228', '231']},{'id': '228', 'type': 'subscript', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '230', 'type': 'integer', 'children': [], 'value': '0'},{'id': '231', 'type': 'string', 'children': [], 'value': '"%Y-%m"'},{'id': '232', 'type': 'if_statement', 'children': ['233', '243']},{'id': '233', 'type': 'comparison_operator', 'children': ['234', '242'], 'value': '=='},{'id': '234', 'type': 'call', 'children': ['235', '240']},{'id': '235', 'type': 'attribute', 'children': ['236', '239']},{'id': '236', 'type': 'subscript', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '238', 'type': 'integer', 'children': [], 'value': '1'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '240', 'type': 'argument_list', 'children': ['241']},{'id': '241', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '242', 'type': 'integer', 'children': [], 'value': '1'},{'id': '243', 'type': 'block', 'children': ['244']},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'assignment', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '247', 'type': 'call', 'children': ['248', '253']},{'id': '248', 'type': 'attribute', 'children': ['249', '252']},{'id': '249', 'type': 'attribute', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'strptime'},{'id': '253', 'type': 'argument_list', 'children': ['254', '257']},{'id': '254', 'type': 'subscript', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '256', 'type': 'integer', 'children': [], 'value': '1'},{'id': '257', 'type': 'string', 'children': [], 'value': '"%Y-%m"'},{'id': '258', 'type': 'if_statement', 'children': ['259', '269']},{'id': '259', 'type': 'comparison_operator', 'children': ['260', '268'], 'value': '=='},{'id': '260', 'type': 'call', 'children': ['261', '266']},{'id': '261', 'type': 'attribute', 'children': ['262', '265']},{'id': '262', 'type': 'subscript', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '264', 'type': 'integer', 'children': [], 'value': '0'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '266', 'type': 'argument_list', 'children': ['267']},{'id': '267', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '268', 'type': 'integer', 'children': [], 'value': '0'},{'id': '269', 'type': 'block', 'children': ['270']},{'id': '270', 'type': 'if_statement', 'children': ['271', '276', '289']},{'id': '271', 'type': 'comparison_operator', 'children': ['272', '275'], 'value': '=='},{'id': '272', 'type': 'subscript', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '274', 'type': 'integer', 'children': [], 'value': '0'},{'id': '275', 'type': 'string', 'children': [], 'value': "'unknown'"},{'id': '276', 'type': 'block', 'children': ['277']},{'id': '277', 'type': 'expression_statement', 'children': ['278']},{'id': '278', 'type': 'assignment', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '280', 'type': 'call', 'children': ['281', '286']},{'id': '281', 'type': 'attribute', 'children': ['282', '285']},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'strptime'},{'id': '286', 'type': 'argument_list', 'children': ['287', '288']},{'id': '287', 'type': 'string', 'children': [], 'value': '"0001"'},{'id': '288', 'type': 'string', 'children': [], 'value': '"%Y"'},{'id': '289', 'type': 'else_clause', 'children': ['290']},{'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': 'from_date'},{'id': '294', 'type': 'call', 'children': ['295', '300']},{'id': '295', 'type': 'attribute', 'children': ['296', '299']},{'id': '296', 'type': 'attribute', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'strptime'},{'id': '300', 'type': 'argument_list', 'children': ['301', '304']},{'id': '301', 'type': 'subscript', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '303', 'type': 'integer', 'children': [], 'value': '0'},{'id': '304', 'type': 'string', 'children': [], 'value': '"%Y"'},{'id': '305', 'type': 'if_statement', 'children': ['306', '316']},{'id': '306', 'type': 'comparison_operator', 'children': ['307', '315'], 'value': '=='},{'id': '307', 'type': 'call', 'children': ['308', '313']},{'id': '308', 'type': 'attribute', 'children': ['309', '312']},{'id': '309', 'type': 'subscript', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '311', 'type': 'integer', 'children': [], 'value': '1'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '313', 'type': 'argument_list', 'children': ['314']},{'id': '314', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '315', 'type': 'integer', 'children': [], 'value': '0'},{'id': '316', 'type': 'block', 'children': ['317']},{'id': '317', 'type': 'if_statement', 'children': ['318', '329', '334']},{'id': '318', 'type': 'boolean_operator', 'children': ['319', '324'], 'value': 'or'},{'id': '319', 'type': 'comparison_operator', 'children': ['320', '323'], 'value': '=='},{'id': '320', 'type': 'subscript', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '322', 'type': 'integer', 'children': [], 'value': '1'},{'id': '323', 'type': 'string', 'children': [], 'value': "'open'"},{'id': '324', 'type': 'comparison_operator', 'children': ['325', '328'], 'value': '=='},{'id': '325', 'type': 'subscript', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '327', 'type': 'integer', 'children': [], 'value': '1'},{'id': '328', 'type': 'string', 'children': [], 'value': "'unknown'"},{'id': '329', 'type': 'block', 'children': ['330']},{'id': '330', 'type': 'expression_statement', 'children': ['331']},{'id': '331', 'type': 'assignment', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '333', 'type': 'string', 'children': [], 'value': "'open'"},{'id': '334', 'type': 'else_clause', 'children': ['335']},{'id': '335', 'type': 'block', 'children': ['336']},{'id': '336', 'type': 'expression_statement', 'children': ['337']},{'id': '337', 'type': 'assignment', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '339', 'type': 'call', 'children': ['340', '345']},{'id': '340', 'type': 'attribute', 'children': ['341', '344']},{'id': '341', 'type': 'attribute', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'strptime'},{'id': '345', 'type': 'argument_list', 'children': ['346', '349']},{'id': '346', 'type': 'subscript', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '348', 'type': 'integer', 'children': [], 'value': '1'},{'id': '349', 'type': 'string', 'children': [], 'value': '"%Y"'},{'id': '350', 'type': 'if_statement', 'children': ['351', '358', '361', '381', '403', '423']},{'id': '351', 'type': 'boolean_operator', 'children': ['352', '355'], 'value': 'and'},{'id': '352', 'type': 'comparison_operator', 'children': ['353', '354'], 'value': '=='},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '354', 'type': 'string', 'children': [], 'value': "'neg'"},{'id': '355', 'type': 'comparison_operator', 'children': ['356', '357'], 'value': '=='},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '357', 'type': 'string', 'children': [], 'value': "'pos'"},{'id': '358', 'type': 'block', 'children': ['359']},{'id': '359', 'type': 'return_statement', 'children': ['360']},{'id': '360', 'type': 'True', 'children': []},{'id': '361', 'type': 'elif_clause', 'children': ['362', '369']},{'id': '362', 'type': 'boolean_operator', 'children': ['363', '366'], 'value': 'and'},{'id': '363', 'type': 'comparison_operator', 'children': ['364', '365'], 'value': '=='},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '365', 'type': 'string', 'children': [], 'value': "'neg'"},{'id': '366', 'type': 'comparison_operator', 'children': ['367', '368'], 'value': '=='},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '368', 'type': 'string', 'children': [], 'value': "'neg'"},{'id': '369', 'type': 'block', 'children': ['370']},{'id': '370', 'type': 'if_statement', 'children': ['371', '378']},{'id': '371', 'type': 'boolean_operator', 'children': ['372', '377'], 'value': 'and'},{'id': '372', 'type': 'boolean_operator', 'children': ['373', '376'], 'value': 'and'},{'id': '373', 'type': 'comparison_operator', 'children': ['374', '375'], 'value': '>='},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '378', 'type': 'block', 'children': ['379']},{'id': '379', 'type': 'return_statement', 'children': ['380']},{'id': '380', 'type': 'True', 'children': []},{'id': '381', 'type': 'elif_clause', 'children': ['382', '400']},{'id': '382', 'type': '()', 'children': ['383']},{'id': '383', 'type': 'boolean_operator', 'children': ['384', '395'], 'value': 'or'},{'id': '384', 'type': 'boolean_operator', 'children': ['385', '390'], 'value': 'or'},{'id': '385', 'type': 'comparison_operator', 'children': ['386', '389'], 'value': '=='},{'id': '386', 'type': 'subscript', 'children': ['387', '388']},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '388', 'type': 'integer', 'children': [], 'value': '1'},{'id': '389', 'type': 'string', 'children': [], 'value': "'unknown'"},{'id': '390', 'type': 'comparison_operator', 'children': ['391', '394'], 'value': '=='},{'id': '391', 'type': 'subscript', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '393', 'type': 'integer', 'children': [], 'value': '1'},{'id': '394', 'type': 'string', 'children': [], 'value': "'open'"},{'id': '395', 'type': 'comparison_operator', 'children': ['396', '399'], 'value': '=='},{'id': '396', 'type': 'subscript', 'children': ['397', '398']},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '398', 'type': 'integer', 'children': [], 'value': '0'},{'id': '399', 'type': 'string', 'children': [], 'value': "'unknown'"},{'id': '400', 'type': 'block', 'children': ['401']},{'id': '401', 'type': 'return_statement', 'children': ['402']},{'id': '402', 'type': 'True', 'children': []},{'id': '403', 'type': 'elif_clause', 'children': ['404', '411']},{'id': '404', 'type': 'boolean_operator', 'children': ['405', '408'], 'value': 'and'},{'id': '405', 'type': 'comparison_operator', 'children': ['406', '407'], 'value': '=='},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '407', 'type': 'string', 'children': [], 'value': "'pos'"},{'id': '408', 'type': 'comparison_operator', 'children': ['409', '410'], 'value': '=='},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '410', 'type': 'string', 'children': [], 'value': "'pos'"},{'id': '411', 'type': 'block', 'children': ['412']},{'id': '412', 'type': 'if_statement', 'children': ['413', '420']},{'id': '413', 'type': 'boolean_operator', 'children': ['414', '419'], 'value': 'and'},{'id': '414', 'type': 'boolean_operator', 'children': ['415', '418'], 'value': 'and'},{'id': '415', 'type': 'comparison_operator', 'children': ['416', '417'], 'value': '<='},{'id': '416', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '417', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '418', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '420', 'type': 'block', 'children': ['421']},{'id': '421', 'type': 'return_statement', 'children': ['422']},{'id': '422', 'type': 'True', 'children': []},{'id': '423', 'type': 'else_clause', 'children': ['424']},{'id': '424', 'type': 'block', 'children': ['425']},{'id': '425', 'type': 'return_statement', 'children': ['426']},{'id': '426', 'type': 'False', 'children': []},{'id': '427', 'type': 'else_clause', 'children': ['428']},{'id': '428', 'type': 'block', 'children': ['429']},{'id': '429', 'type': 'return_statement', 'children': ['430']},{'id': '430', 'type': 'False', 'children': []}
def is_valid_interval(edtf_candidate): from_date = None to_date = None end, start = 'pos', 'pos' if edtf_candidate.count('/') == 1: edtf_candidate = replace_all(edtf_candidate, interval_replacements) edtf_candidate = re.sub(U_PATTERN, replace_u, edtf_candidate) parts = edtf_candidate.split('/') if parts[0].startswith("-"): start = 'neg' parts[0] = parts[0][1:] if parts[1].startswith("-"): end = 'neg' parts[1] = parts[1][1:] if start == 'pos' and end == 'neg': return False if parts[0].startswith("0000") or parts[1].startswith("0000"): return zero_year_special_case(parts[0], parts[1], start, end) if parts[0].count("-") == 2: from_date = datetime.datetime.strptime(parts[0], "%Y-%m-%d") if parts[1].count("-") == 2: to_date = datetime.datetime.strptime(parts[1], "%Y-%m-%d") if parts[0].count("-") == 1: from_date = datetime.datetime.strptime(parts[0], "%Y-%m") if parts[1].count("-") == 1: to_date = datetime.datetime.strptime(parts[1], "%Y-%m") if parts[0].count("-") == 0: if parts[0] == 'unknown': from_date = datetime.datetime.strptime("0001", "%Y") else: from_date = datetime.datetime.strptime(parts[0], "%Y") if parts[1].count("-") == 0: if parts[1] == 'open' or parts[1] == 'unknown': to_date = 'open' else: to_date = datetime.datetime.strptime(parts[1], "%Y") if start == 'neg' and end == 'pos': return True elif start == 'neg' and end == 'neg': if from_date >= to_date and from_date and to_date: return True elif ( parts[1] == 'unknown' or parts[1] == 'open' or parts[0] == 'unknown' ): return True elif start == 'pos' and end == 'pos': if from_date <= to_date and from_date and to_date: return True else: return False else: return False
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'template'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '10']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'dictionary_splat_pattern', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '12', 'type': 'block', 'children': ['13', '17', '236']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'pkey'},{'id': '16', 'type': 'string', 'children': [], 'value': '"_template_extends__"'},{'id': '17', 'type': 'function_definition', 'children': ['18', '19', '21']},{'id': '18', 'type': 'function_name', 'children': [], 'value': 'decorator'},{'id': '19', 'type': 'parameters', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'if_statement', 'children': ['23', '29', '147']},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'isclass'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '29', 'type': 'block', 'children': ['30', '36', '46', '95', '103', '111', '117', '124', '136', '145']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'layout_'},{'id': '33', 'type': 'boolean_operator', 'children': ['34', '35'], 'value': 'or'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'extends'},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45']},{'id': '44', 'type': 'string', 'children': [], 'value': '"extends"'},{'id': '45', 'type': 'None', 'children': []},{'id': '46', 'type': 'if_statement', 'children': ['47', '54']},{'id': '47', 'type': 'boolean_operator', 'children': ['48', '49'], 'value': 'and'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'extends'},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '51', 'type': 'argument_list', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'extends'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'pkey'},{'id': '54', 'type': 'block', 'children': ['55', '67', '81']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '58', 'type': 'call', 'children': ['59', '66']},{'id': '59', 'type': 'attribute', 'children': ['60', '65']},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'extends'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'pkey'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '66', 'type': 'argument_list', 'children': []},{'id': '67', 'type': 'if_statement', 'children': ['68', '71']},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'in'},{'id': '69', 'type': 'string', 'children': [], 'value': '"layout"'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'layout_'},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'string', 'children': [], 'value': '"layout"'},{'id': '81', 'type': 'for_statement', 'children': ['82', '85', '86']},{'id': '82', 'type': 'pattern_list', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '86', 'type': 'block', 'children': ['87']},{'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': 'kwargs'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '92', 'type': 'argument_list', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '95', 'type': 'if_statement', 'children': ['96', '98']},{'id': '96', 'type': 'not_operator', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'layout_'},{'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': 'layout_'},{'id': '102', 'type': 'string', 'children': [], 'value': '"layout.html"'},{'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': 'kwargs'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '108', 'type': 'argument_list', 'children': ['109', '110']},{'id': '109', 'type': 'string', 'children': [], 'value': '"brand_name"'},{'id': '110', 'type': 'string', 'children': [], 'value': '""'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '116']},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '115', 'type': 'string', 'children': [], 'value': '"layout"'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'layout_'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'setattr'},{'id': '120', 'type': 'argument_list', 'children': ['121', '122', '123']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'pkey'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'setattr'},{'id': '127', 'type': 'argument_list', 'children': ['128', '129', '130']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '129', 'type': 'string', 'children': [], 'value': '"base_layout"'},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'string', 'children': [], 'value': '"layout"'},{'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': 'f'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'keyword_argument', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'TEMPLATE_CONTEXT'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '145', 'type': 'return_statement', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '147', 'type': 'else_clause', 'children': ['148']},{'id': '148', 'type': 'block', 'children': ['149', '234']},{'id': '149', 'type': 'decorated_definition', 'children': ['150', '157']},{'id': '150', 'type': 'decorator', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'functools'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'wraps'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '157', 'type': 'function_definition', 'children': ['158', '159', '164']},{'id': '158', 'type': 'function_name', 'children': [], 'value': 'wrap'},{'id': '159', 'type': 'parameters', 'children': ['160', '162']},{'id': '160', 'type': 'list_splat_pattern', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'args2'},{'id': '162', 'type': 'dictionary_splat_pattern', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'kwargs2'},{'id': '164', 'type': 'block', 'children': ['165', '175', '232']},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '170', 'type': 'argument_list', 'children': ['171', '173']},{'id': '171', 'type': 'list_splat', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'args2'},{'id': '173', 'type': 'dictionary_splat', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'kwargs2'},{'id': '175', 'type': 'if_statement', 'children': ['176', '185']},{'id': '176', 'type': 'boolean_operator', 'children': ['177', '182'], 'value': 'or'},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '179', 'type': 'argument_list', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '182', 'type': 'comparison_operator', 'children': ['183', '184'], 'value': 'is'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '184', 'type': 'None', 'children': []},{'id': '185', 'type': 'block', 'children': ['186', '192', '203', '214']},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '189', 'type': 'boolean_operator', 'children': ['190', '191'], 'value': 'or'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '191', 'type': 'dictionary', 'children': []},{'id': '192', 'type': 'if_statement', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'page'},{'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': 'response'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '200', 'type': 'argument_list', 'children': ['201', '202']},{'id': '201', 'type': 'string', 'children': [], 'value': '"template_"'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '203', 'type': 'if_statement', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '205', 'type': 'block', 'children': ['206']},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'call', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '211', 'type': 'argument_list', 'children': ['212', '213']},{'id': '212', 'type': 'string', 'children': [], 'value': '"layout_"'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '214', 'type': 'for_statement', 'children': ['215', '218', '223']},{'id': '215', 'type': 'pattern_list', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '218', 'type': 'call', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '222', 'type': 'argument_list', 'children': []},{'id': '223', 'type': 'block', 'children': ['224']},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'call', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '229', 'type': 'argument_list', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '232', 'type': 'return_statement', 'children': ['233']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '234', 'type': 'return_statement', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'wrap'},{'id': '236', 'type': 'return_statement', 'children': ['237']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'decorator'}
def template(page=None, layout=None, **kwargs): pkey = "_template_extends__" def decorator(f): if inspect.isclass(f): layout_ = layout or page extends = kwargs.pop("extends", None) if extends and hasattr(extends, pkey): items = getattr(extends, pkey).items() if "layout" in items: layout_ = items.pop("layout") for k, v in items: kwargs.setdefault(k, v) if not layout_: layout_ = "layout.html" kwargs.setdefault("brand_name", "") kwargs["layout"] = layout_ setattr(f, pkey, kwargs) setattr(f, "base_layout", kwargs.get("layout")) f.g(TEMPLATE_CONTEXT=kwargs) return f else: @functools.wraps(f) def wrap(*args2, **kwargs2): response = f(*args2, **kwargs2) if isinstance(response, dict) or response is None: response = response or {} if page: response.setdefault("template_", page) if layout: response.setdefault("layout_", layout) for k, v in kwargs.items(): response.setdefault(k, v) return response return wrap return decorator
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'getargspec'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '5', 'type': 'block', 'children': ['6', '18', '122', '135', '200']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '13']},{'id': '8', 'type': 'pattern_list', 'children': ['9', '10', '11', '12']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'argnames'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'varargs'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'varkw'},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_defaults'},{'id': '13', 'type': 'expression_list', 'children': ['14', '15', '16', '17']},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'if_statement', 'children': ['19', '32', '46', '93', '115']},{'id': '19', 'type': 'boolean_operator', 'children': ['20', '26'], 'value': 'or'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'isfunction'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'ismethod'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '40']},{'id': '35', 'type': 'pattern_list', 'children': ['36', '37', '38', '39']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'argnames'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'varargs'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'varkw'},{'id': '39', 'type': 'identifier', 'children': [], 'value': '_defaults'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'getargspec'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '46', 'type': 'elif_clause', 'children': ['47', '53']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'isclass'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'if_statement', 'children': ['55', '63', '76']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'ismethoddescriptor'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '62', 'type': 'identifier', 'children': [], 'value': '__init__'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '71']},{'id': '66', 'type': 'pattern_list', 'children': ['67', '68', '69', '70']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'argnames'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'varargs'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'varkw'},{'id': '70', 'type': 'identifier', 'children': [], 'value': '_defaults'},{'id': '71', 'type': 'expression_list', 'children': ['72', '73', '74', '75']},{'id': '72', 'type': 'list', 'children': [], 'value': '[]'},{'id': '73', 'type': 'False', 'children': []},{'id': '74', 'type': 'False', 'children': []},{'id': '75', 'type': 'None', 'children': []},{'id': '76', 'type': 'else_clause', 'children': ['77']},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '85']},{'id': '80', 'type': 'pattern_list', 'children': ['81', '82', '83', '84']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'argnames'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'varargs'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'varkw'},{'id': '84', 'type': 'identifier', 'children': [], 'value': '_defaults'},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'getargspec'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '92', 'type': 'identifier', 'children': [], 'value': '__init__'},{'id': '93', 'type': 'elif_clause', 'children': ['94', '99']},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '96', 'type': 'argument_list', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '98', 'type': 'string', 'children': [], 'value': "'__call__'"},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '107']},{'id': '102', 'type': 'pattern_list', 'children': ['103', '104', '105', '106']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'argnames'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'varargs'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'varkw'},{'id': '106', 'type': 'identifier', 'children': [], 'value': '_defaults'},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'getargspec'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '114', 'type': 'identifier', 'children': [], 'value': '__call__'},{'id': '115', 'type': 'else_clause', 'children': ['116']},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'raise_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'string', 'children': [], 'value': '"Object not callable?"'},{'id': '122', 'type': 'if_statement', 'children': ['123', '130']},{'id': '123', 'type': 'boolean_operator', 'children': ['124', '125'], 'value': 'and'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'argnames'},{'id': '125', 'type': 'comparison_operator', 'children': ['126', '129'], 'value': '=='},{'id': '126', 'type': 'subscript', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'argnames'},{'id': '128', 'type': 'integer', 'children': [], 'value': '0'},{'id': '129', 'type': 'string', 'children': [], 'value': "'self'"},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'delete_statement', 'children': ['132']},{'id': '132', 'type': 'subscript', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'argnames'},{'id': '134', 'type': 'integer', 'children': [], 'value': '0'},{'id': '135', 'type': 'if_statement', 'children': ['136', '139', '150']},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '138'], 'value': 'is'},{'id': '137', 'type': 'identifier', 'children': [], 'value': '_defaults'},{'id': '138', 'type': 'None', 'children': []},{'id': '139', 'type': 'block', 'children': ['140', '144']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': '_defaults'},{'id': '143', 'type': 'list', 'children': [], 'value': '[]'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '149', 'type': 'argument_list', 'children': []},{'id': '150', 'type': 'else_clause', 'children': ['151']},{'id': '151', 'type': 'block', 'children': ['152', '158', '165', '171', '177', '194']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '157', 'type': 'argument_list', 'children': []},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': '_defaults'},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': '_defaults'},{'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': '_defaults'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '170', 'type': 'argument_list', 'children': []},{'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': 'argnames'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '176', 'type': 'argument_list', 'children': []},{'id': '177', 'type': 'for_statement', 'children': ['178', '181', '185']},{'id': '178', 'type': 'pattern_list', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '181', 'type': 'call', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': '_defaults'},{'id': '185', 'type': 'block', 'children': ['186']},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '193']},{'id': '188', 'type': 'subscript', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '190', 'type': 'subscript', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'argnames'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'default'},{'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': 'argnames'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '199', 'type': 'argument_list', 'children': []},{'id': '200', 'type': 'return_statement', 'children': ['201']},{'id': '201', 'type': 'expression_list', 'children': ['202', '203', '204', '208']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'argnames'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '204', 'type': 'conditional_expression', 'children': ['205', '206', '207'], 'value': 'if'},{'id': '205', 'type': 'True', 'children': []},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'varargs'},{'id': '207', 'type': 'False', 'children': []},{'id': '208', 'type': 'conditional_expression', 'children': ['209', '210', '211'], 'value': 'if'},{'id': '209', 'type': 'True', 'children': []},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'varkw'},{'id': '211', 'type': 'False', 'children': []}
def getargspec(obj): argnames, varargs, varkw, _defaults = None, None, None, None if inspect.isfunction(obj) or inspect.ismethod(obj): argnames, varargs, varkw, _defaults = inspect.getargspec(obj) elif inspect.isclass(obj): if inspect.ismethoddescriptor(obj.__init__): argnames, varargs, varkw, _defaults = [], False, False, None else: argnames, varargs, varkw, _defaults = inspect.getargspec(obj.__init__) elif hasattr(obj, '__call__'): argnames, varargs, varkw, _defaults = inspect.getargspec(obj.__call__) else: raise TypeError("Object not callable?") if argnames and argnames[0] == 'self': del argnames[0] if _defaults is None: _defaults = [] defaults = dict() else: defaults = dict() _defaults = list(_defaults) _defaults.reverse() argnames.reverse() for i, default in enumerate(_defaults): defaults[argnames[i]] = default argnames.reverse() return argnames, defaults, True if varargs else False, True if varkw else False
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_find_overlap'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'find_method'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'get_method'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'overlap_function'},{'id': '9', 'type': 'block', 'children': ['10', '14', '69']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '13', 'type': 'list', 'children': [], 'value': '[]'},{'id': '14', 'type': 'for_statement', 'children': ['15', '16', '17']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '17', 'type': 'block', 'children': ['18', '30', '44', '62']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'candidates'},{'id': '21', 'type': 'await', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '28']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'find_method'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '30', 'type': 'if_statement', 'children': ['31', '33']},{'id': '31', 'type': 'not_operator', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'candidates'},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'raise_statement', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'string', 'children': [], 'value': "'no result found for {!r}'"},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '47', 'type': 'await', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '54']},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '51', 'type': 'argument_list', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'get_method'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'id_'},{'id': '57', 'type': 'attribute', 'children': ['58', '61']},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'candidates'},{'id': '60', 'type': 'integer', 'children': [], 'value': '0'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'id_'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '69', 'type': 'return_statement', 'children': ['70']},{'id': '70', 'type': 'await', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'overlap_function'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'client'}
async def _find_overlap(queries, client, find_method, get_method, overlap_function): results = [] for query in queries: candidates = await getattr(client, find_method)(query) if not candidates: raise ValueError('no result found for {!r}'.format(query)) result = await getattr(client, get_method)(id_=candidates[0].id_) results.append(result) return await overlap_function(results, client)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'power'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'set_'},{'id': '5', 'type': 'block', 'children': ['6', '11', '35']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'call', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'ensure_countable'},{'id': '9', 'type': 'argument_list', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'set_'},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'from_iterable'},{'id': '18', 'type': 'generator_expression', 'children': ['19', '24']},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'combinations'},{'id': '21', 'type': 'argument_list', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'set_'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '24', 'type': 'for_in_clause', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'xrange'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'binary_operator', 'children': ['30', '34'], 'value': '+'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'set_'},{'id': '34', 'type': 'integer', 'children': [], 'value': '1'},{'id': '35', 'type': 'return_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': '_harmonize_subset_types'},{'id': '38', 'type': 'argument_list', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'set_'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'result'}
def power(set_): ensure_countable(set_) result = chain.from_iterable(combinations(set_, r) for r in xrange(len(set_) + 1)) return _harmonize_subset_types(set_, result)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'generate_pws_in_order'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'filter_func'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'N_max'},{'id': '11', 'type': 'float', 'children': [], 'value': '1e6'},{'id': '12', 'type': 'block', 'children': ['13', '23', '32', '36', '42', '48', '286']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'states'},{'id': '16', 'type': 'list', 'children': ['17'], 'value': '[(-1.0, helper.START)]'},{'id': '17', 'type': 'tuple', 'children': ['18', '20']},{'id': '18', 'type': 'unary_operator', 'children': ['19'], 'value': '-'},{'id': '19', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'helper'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'START'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'p_min'},{'id': '26', 'type': 'binary_operator', 'children': ['27', '28'], 'value': '/'},{'id': '27', 'type': 'float', 'children': [], 'value': '1e-9'},{'id': '28', 'type': '()', 'children': ['29']},{'id': '29', 'type': 'binary_operator', 'children': ['30', '31'], 'value': '**'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '31', 'type': 'integer', 'children': [], 'value': '2'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'ret'},{'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': 'done'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'already_added_in_heap'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '47', 'type': 'argument_list', 'children': []},{'id': '48', 'type': 'while_statement', 'children': ['49', '62']},{'id': '49', 'type': 'boolean_operator', 'children': ['50', '56'], 'value': 'and'},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '55'], 'value': '<'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '61'], 'value': '>'},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'states'},{'id': '61', 'type': 'integer', 'children': [], 'value': '0'},{'id': '62', 'type': 'block', 'children': ['63', '74', '84', '90', '104', '214']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '68']},{'id': '65', 'type': 'pattern_list', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'heapq'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'heappop'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'states'},{'id': '74', 'type': 'if_statement', 'children': ['75', '78']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': '<'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '77', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'p'},{'id': '82', 'type': 'unary_operator', 'children': ['83'], 'value': '-'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '84', 'type': 'if_statement', 'children': ['85', '88']},{'id': '85', 'type': 'comparison_operator', 'children': ['86', '87'], 'value': 'in'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'done'},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'continue_statement', 'children': []},{'id': '90', 'type': 'assert_statement', 'children': ['91', '98']},{'id': '91', 'type': 'comparison_operator', 'children': ['92', '95'], 'value': '=='},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '94', 'type': 'integer', 'children': [], 'value': '0'},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'helper'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'START'},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'string', 'children': [], 'value': '"Broken s: {!r}"'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '104', 'type': 'if_statement', 'children': ['105', '113', '150']},{'id': '105', 'type': 'comparison_operator', 'children': ['106', '110'], 'value': '=='},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '108', 'type': 'unary_operator', 'children': ['109'], 'value': '-'},{'id': '109', 'type': 'integer', 'children': [], 'value': '1'},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'helper'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'END'},{'id': '113', 'type': 'block', 'children': ['114', '121', '131']},{'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': 'done'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'clean_s'},{'id': '124', 'type': 'subscript', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '126', 'type': 'slice', 'children': ['127', '128', '129']},{'id': '127', 'type': 'integer', 'children': [], 'value': '1'},{'id': '128', 'type': 'colon', 'children': []},{'id': '129', 'type': 'unary_operator', 'children': ['130'], 'value': '-'},{'id': '130', 'type': 'integer', 'children': [], 'value': '1'},{'id': '131', 'type': 'if_statement', 'children': ['132', '140']},{'id': '132', 'type': 'boolean_operator', 'children': ['133', '136'], 'value': 'or'},{'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': 'is'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'filter_func'},{'id': '135', 'type': 'None', 'children': []},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'filter_func'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'clean_s'},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'tuple', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'clean_s'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '150', 'type': 'else_clause', 'children': ['151']},{'id': '151', 'type': 'block', 'children': ['152']},{'id': '152', 'type': 'for_statement', 'children': ['153', '156', '166']},{'id': '153', 'type': 'pattern_list', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '156', 'type': 'call', 'children': ['157', '165']},{'id': '157', 'type': 'attribute', 'children': ['158', '164']},{'id': '158', 'type': 'call', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '161', 'type': 'identifier', 'children': [], 'value': '_get_next'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '165', 'type': 'argument_list', 'children': []},{'id': '166', 'type': 'block', 'children': ['167', '190', '199']},{'id': '167', 'type': 'if_statement', 'children': ['168', '188']},{'id': '168', 'type': '()', 'children': ['169']},{'id': '169', 'type': 'boolean_operator', 'children': ['170', '182'], 'value': 'or'},{'id': '170', 'type': 'boolean_operator', 'children': ['171', '176'], 'value': 'or'},{'id': '171', 'type': 'comparison_operator', 'children': ['172', '175'], 'value': '<'},{'id': '172', 'type': 'binary_operator', 'children': ['173', '174'], 'value': '*'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'p_min'},{'id': '176', 'type': 'comparison_operator', 'children': ['177', '181'], 'value': 'in'},{'id': '177', 'type': '()', 'children': ['178']},{'id': '178', 'type': 'binary_operator', 'children': ['179', '180'], 'value': '+'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'done'},{'id': '182', 'type': 'comparison_operator', 'children': ['183', '187'], 'value': 'in'},{'id': '183', 'type': '()', 'children': ['184']},{'id': '184', 'type': 'binary_operator', 'children': ['185', '186'], 'value': '+'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'already_added_in_heap'},{'id': '188', 'type': 'block', 'children': ['189']},{'id': '189', 'type': 'continue_statement', 'children': []},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'already_added_in_heap'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'binary_operator', 'children': ['197', '198'], 'value': '+'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'c'},{'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': 'heapq'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'heappush'},{'id': '204', 'type': 'argument_list', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'states'},{'id': '206', 'type': 'tuple', 'children': ['207', '211']},{'id': '207', 'type': 'binary_operator', 'children': ['208', '210'], 'value': '*'},{'id': '208', 'type': 'unary_operator', 'children': ['209'], 'value': '-'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '211', 'type': 'binary_operator', 'children': ['212', '213'], 'value': '+'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '214', 'type': 'if_statement', 'children': ['215', '225']},{'id': '215', 'type': 'comparison_operator', 'children': ['216', '220'], 'value': '>'},{'id': '216', 'type': 'call', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'states'},{'id': '220', 'type': 'binary_operator', 'children': ['221', '224'], 'value': '/'},{'id': '221', 'type': 'binary_operator', 'children': ['222', '223'], 'value': '*'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'N_max'},{'id': '223', 'type': 'integer', 'children': [], 'value': '3'},{'id': '224', 'type': 'integer', 'children': [], 'value': '2'},{'id': '225', 'type': 'block', 'children': ['226', '245', '264', '281']},{'id': '226', 'type': 'expression_statement', 'children': ['227']},{'id': '227', 'type': 'call', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '229', 'type': 'argument_list', 'children': ['230']},{'id': '230', 'type': 'call', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'string', 'children': [], 'value': '"Heap size: {}. ret={}. (expected: {}) s={!r}"'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '234', 'type': 'argument_list', 'children': ['235', '239', '243', '244']},{'id': '235', 'type': 'call', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '237', 'type': 'argument_list', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'states'},{'id': '239', 'type': 'call', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '241', 'type': 'argument_list', 'children': ['242']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'call', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '248', 'type': 'argument_list', 'children': ['249']},{'id': '249', 'type': 'call', 'children': ['250', '253']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'string', 'children': [], 'value': '"The size of states={}. Still need={} pws. Truncating"'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '253', 'type': 'argument_list', 'children': ['254', '258']},{'id': '254', 'type': 'call', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '256', 'type': 'argument_list', 'children': ['257']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'states'},{'id': '258', 'type': 'binary_operator', 'children': ['259', '260'], 'value': '-'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '260', 'type': 'call', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '262', 'type': 'argument_list', 'children': ['263']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'assignment', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'states'},{'id': '267', 'type': 'call', 'children': ['268', '271']},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'heapq'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'nsmallest'},{'id': '271', 'type': 'argument_list', 'children': ['272', '280']},{'id': '272', 'type': 'call', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '274', 'type': 'argument_list', 'children': ['275']},{'id': '275', 'type': 'binary_operator', 'children': ['276', '279'], 'value': '/'},{'id': '276', 'type': 'binary_operator', 'children': ['277', '278'], 'value': '*'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'N_max'},{'id': '278', 'type': 'integer', 'children': [], 'value': '3'},{'id': '279', 'type': 'integer', 'children': [], 'value': '4'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'states'},{'id': '281', 'type': 'expression_statement', 'children': ['282']},{'id': '282', 'type': 'call', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '284', 'type': 'argument_list', 'children': ['285']},{'id': '285', 'type': 'string', 'children': [], 'value': '"Done"'},{'id': '286', 'type': 'return_statement', 'children': ['287']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'ret'}
def generate_pws_in_order(self, n, filter_func=None, N_max=1e6): states = [(-1.0, helper.START)] p_min = 1e-9 / (n**2) ret = [] done = set() already_added_in_heap = set() while len(ret) < n and len(states) > 0: p, s = heapq.heappop(states) if p < 0: p = -p if s in done: continue assert s[0] == helper.START, "Broken s: {!r}".format(s) if s[-1] == helper.END: done.add(s) clean_s = s[1:-1] if filter_func is None or filter_func(clean_s): ret.append((clean_s, p)) else: for c, f in self._get_next(s).items(): if (f*p < p_min or (s+c) in done or (s+c) in already_added_in_heap): continue already_added_in_heap.add(s+c) heapq.heappush(states, (-f*p, s+c)) if len(states) > N_max * 3 / 2: print("Heap size: {}. ret={}. (expected: {}) s={!r}" .format(len(states), len(ret), n, s)) print("The size of states={}. Still need={} pws. Truncating" .format(len(states), n - len(ret))) states = heapq.nsmallest(int(N_max * 3/4), states) print("Done") return ret
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'expand_seed'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'start_seed'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'num_iterations'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '8', 'type': 'block', 'children': ['9', '24', '34']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'call', 'children': ['11', '16']},{'id': '11', 'type': 'attribute', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'grd'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'set_tile'},{'id': '16', 'type': 'argument_list', 'children': ['17', '20', '23']},{'id': '17', 'type': 'subscript', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'start_seed'},{'id': '19', 'type': 'integer', 'children': [], 'value': '0'},{'id': '20', 'type': 'subscript', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'start_seed'},{'id': '22', 'type': 'integer', 'children': [], 'value': '1'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'cur_pos'},{'id': '27', 'type': 'list', 'children': ['28', '31'], 'value': '[start_seed[0], start_seed[1]]'},{'id': '28', 'type': 'subscript', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'start_seed'},{'id': '30', 'type': 'integer', 'children': [], 'value': '0'},{'id': '31', 'type': 'subscript', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'start_seed'},{'id': '33', 'type': 'integer', 'children': [], 'value': '1'},{'id': '34', 'type': 'while_statement', 'children': ['35', '38']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': '>'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'num_iterations'},{'id': '37', 'type': 'integer', 'children': [], 'value': '0'},{'id': '38', 'type': 'block', 'children': ['39', '43', '144', '158', '172', '187', '202', '217', '232']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'augmented_assignment', 'children': ['41', '42'], 'value': '-='},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'num_iterations'},{'id': '42', 'type': 'integer', 'children': [], 'value': '1'},{'id': '43', 'type': 'for_statement', 'children': ['44', '45', '66']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '47', 'type': 'argument_list', 'children': ['48', '57']},{'id': '48', 'type': 'binary_operator', 'children': ['49', '52'], 'value': '-'},{'id': '49', 'type': 'subscript', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'cur_pos'},{'id': '51', 'type': 'integer', 'children': [], 'value': '0'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'randint'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56']},{'id': '55', 'type': 'integer', 'children': [], 'value': '0'},{'id': '56', 'type': 'integer', 'children': [], 'value': '2'},{'id': '57', 'type': 'binary_operator', 'children': ['58', '61'], 'value': '+'},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'cur_pos'},{'id': '60', 'type': 'integer', 'children': [], 'value': '0'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'randint'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65']},{'id': '64', 'type': 'integer', 'children': [], 'value': '0'},{'id': '65', 'type': 'integer', 'children': [], 'value': '2'},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'for_statement', 'children': ['68', '69', '90']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '71', 'type': 'argument_list', 'children': ['72', '81']},{'id': '72', 'type': 'binary_operator', 'children': ['73', '76'], 'value': '-'},{'id': '73', 'type': 'subscript', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'cur_pos'},{'id': '75', 'type': 'integer', 'children': [], 'value': '1'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'randint'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80']},{'id': '79', 'type': 'integer', 'children': [], 'value': '0'},{'id': '80', 'type': 'integer', 'children': [], 'value': '2'},{'id': '81', 'type': 'binary_operator', 'children': ['82', '85'], 'value': '+'},{'id': '82', 'type': 'subscript', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'cur_pos'},{'id': '84', 'type': 'integer', 'children': [], 'value': '1'},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'randint'},{'id': '87', 'type': 'argument_list', 'children': ['88', '89']},{'id': '88', 'type': 'integer', 'children': [], 'value': '0'},{'id': '89', 'type': 'integer', 'children': [], 'value': '2'},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'if_statement', 'children': ['92', '115']},{'id': '92', 'type': 'boolean_operator', 'children': ['93', '108'], 'value': 'and'},{'id': '93', 'type': 'boolean_operator', 'children': ['94', '105'], 'value': 'and'},{'id': '94', 'type': 'boolean_operator', 'children': ['95', '102'], 'value': 'and'},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': '<'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '97', 'type': 'attribute', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'grd'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'grid_width'},{'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': '>='},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '104', 'type': 'integer', 'children': [], 'value': '0'},{'id': '105', 'type': 'comparison_operator', 'children': ['106', '107'], 'value': '>='},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '107', 'type': 'integer', 'children': [], 'value': '0'},{'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': '<'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '110', 'type': 'attribute', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'grd'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'grid_height'},{'id': '115', 'type': 'block', 'children': ['116']},{'id': '116', 'type': 'if_statement', 'children': ['117', '128']},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '127'], 'value': '!='},{'id': '118', 'type': 'call', 'children': ['119', '124']},{'id': '119', 'type': 'attribute', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'grd'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'get_tile'},{'id': '124', 'type': 'argument_list', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '128', 'type': 'block', 'children': ['129', '140']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '136']},{'id': '131', 'type': 'attribute', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'grd'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'set_tile'},{'id': '136', 'type': 'argument_list', 'children': ['137', '138', '139']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'TERRAIN_LAND'},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'augmented_assignment', 'children': ['142', '143'], 'value': '-='},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'num_iterations'},{'id': '143', 'type': 'integer', 'children': [], 'value': '1'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'new_x'},{'id': '147', 'type': 'binary_operator', 'children': ['148', '157'], 'value': '-'},{'id': '148', 'type': 'binary_operator', 'children': ['149', '152'], 'value': '+'},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'cur_pos'},{'id': '151', 'type': 'integer', 'children': [], 'value': '0'},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'randint'},{'id': '154', 'type': 'argument_list', 'children': ['155', '156']},{'id': '155', 'type': 'integer', 'children': [], 'value': '0'},{'id': '156', 'type': 'integer', 'children': [], 'value': '3'},{'id': '157', 'type': 'integer', 'children': [], 'value': '2'},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'new_y'},{'id': '161', 'type': 'binary_operator', 'children': ['162', '171'], 'value': '-'},{'id': '162', 'type': 'binary_operator', 'children': ['163', '166'], 'value': '+'},{'id': '163', 'type': 'subscript', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'cur_pos'},{'id': '165', 'type': 'integer', 'children': [], 'value': '1'},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'randint'},{'id': '168', 'type': 'argument_list', 'children': ['169', '170']},{'id': '169', 'type': 'integer', 'children': [], 'value': '0'},{'id': '170', 'type': 'integer', 'children': [], 'value': '3'},{'id': '171', 'type': 'integer', 'children': [], 'value': '2'},{'id': '172', 'type': 'if_statement', 'children': ['173', '182']},{'id': '173', 'type': 'comparison_operator', 'children': ['174', '175'], 'value': '>'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'new_x'},{'id': '175', 'type': 'binary_operator', 'children': ['176', '181'], 'value': '-'},{'id': '176', 'type': 'attribute', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'grd'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'grid_width'},{'id': '181', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'new_x'},{'id': '186', 'type': 'integer', 'children': [], 'value': '0'},{'id': '187', 'type': 'if_statement', 'children': ['188', '197']},{'id': '188', 'type': 'comparison_operator', 'children': ['189', '190'], 'value': '>'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'new_y'},{'id': '190', 'type': 'binary_operator', 'children': ['191', '196'], 'value': '-'},{'id': '191', 'type': 'attribute', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'grd'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'grid_height'},{'id': '196', 'type': 'integer', 'children': [], 'value': '1'},{'id': '197', 'type': 'block', 'children': ['198']},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'new_y'},{'id': '201', 'type': 'integer', 'children': [], 'value': '0'},{'id': '202', 'type': 'if_statement', 'children': ['203', '206']},{'id': '203', 'type': 'comparison_operator', 'children': ['204', '205'], 'value': '<'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'new_x'},{'id': '205', 'type': 'integer', 'children': [], 'value': '0'},{'id': '206', 'type': 'block', 'children': ['207']},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'new_x'},{'id': '210', 'type': 'binary_operator', 'children': ['211', '216'], 'value': '-'},{'id': '211', 'type': 'attribute', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'grd'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'grid_width'},{'id': '216', 'type': 'integer', 'children': [], 'value': '1'},{'id': '217', 'type': 'if_statement', 'children': ['218', '221']},{'id': '218', 'type': 'comparison_operator', 'children': ['219', '220'], 'value': '<'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'new_y'},{'id': '220', 'type': 'integer', 'children': [], 'value': '0'},{'id': '221', 'type': 'block', 'children': ['222']},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'new_y'},{'id': '225', 'type': 'binary_operator', 'children': ['226', '231'], 'value': '-'},{'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': 'grd'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'grid_height'},{'id': '231', 'type': 'integer', 'children': [], 'value': '1'},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'cur_pos'},{'id': '235', 'type': 'list', 'children': ['236', '237'], 'value': '[new_y, new_x]'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'new_y'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'new_x'}
def expand_seed(self, start_seed, num_iterations, val): self.grd.set_tile(start_seed[0], start_seed[1], val) cur_pos = [start_seed[0], start_seed[1]] while num_iterations > 0: num_iterations -= 1 for y in range(cur_pos[0]-randint(0,2), cur_pos[0] + randint(0,2)): for x in range(cur_pos[1]-randint(0,2), cur_pos[1] + randint(0,2)): if x < self.grd.grid_width and x >= 0 and y >= 0 and y < self.grd.grid_height: if self.grd.get_tile(y,x) != val: self.grd.set_tile(y, x, TERRAIN_LAND) num_iterations -= 1 new_x = cur_pos[0] + randint(0,3)-2 new_y = cur_pos[1] + randint(0,3)-2 if new_x > self.grd.grid_width - 1: new_x = 0 if new_y > self.grd.grid_height - 1: new_y = 0 if new_x < 0: new_x = self.grd.grid_width - 1 if new_y < 0: new_y = self.grd.grid_height - 1 cur_pos = [new_y, new_x]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'denoise_grid'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'expand'},{'id': '8', 'type': 'integer', 'children': [], 'value': '1'},{'id': '9', 'type': 'block', 'children': ['10', '46', '240']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'updated_grid'},{'id': '13', 'type': 'list_comprehension', 'children': ['14', '35', '36']},{'id': '14', 'type': 'list_comprehension', 'children': ['15', '24', '25']},{'id': '15', 'type': 'call', 'children': ['16', '21']},{'id': '16', 'type': 'attribute', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'grd'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'get_tile'},{'id': '21', 'type': 'argument_list', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '24', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '25', 'type': 'for_in_clause', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'attribute', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'grd'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'grid_width'},{'id': '35', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '36', 'type': 'for_in_clause', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'attribute', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'grd'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'grid_height'},{'id': '46', 'type': 'for_statement', 'children': ['47', '48', '60']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'binary_operator', 'children': ['52', '59'], 'value': '-'},{'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': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'grd'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'get_grid_height'},{'id': '58', 'type': 'argument_list', 'children': []},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'expand'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'for_statement', 'children': ['62', '63', '75']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'binary_operator', 'children': ['67', '74'], 'value': '-'},{'id': '67', 'type': 'call', 'children': ['68', '73']},{'id': '68', 'type': 'attribute', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'grd'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'get_grid_width'},{'id': '73', 'type': 'argument_list', 'children': []},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'expand'},{'id': '75', 'type': 'block', 'children': ['76', '92']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '83']},{'id': '78', 'type': 'subscript', 'children': ['79', '82']},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'updated_grid'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '83', 'type': 'call', 'children': ['84', '89']},{'id': '84', 'type': 'attribute', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'grd'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'get_tile'},{'id': '89', 'type': 'argument_list', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '92', 'type': 'if_statement', 'children': ['93', '104']},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '103'], 'value': '=='},{'id': '94', 'type': 'call', 'children': ['95', '100']},{'id': '95', 'type': 'attribute', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'grd'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'get_tile'},{'id': '100', 'type': 'argument_list', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '104', 'type': 'block', 'children': ['105']},{'id': '105', 'type': 'for_statement', 'children': ['106', '107', '113']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '109', 'type': 'argument_list', 'children': ['110', '112']},{'id': '110', 'type': 'unary_operator', 'children': ['111'], 'value': '-'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'expand'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'expand'},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'for_statement', 'children': ['115', '116', '122']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '118', 'type': 'argument_list', 'children': ['119', '121']},{'id': '119', 'type': 'unary_operator', 'children': ['120'], 'value': '-'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'expand'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'expand'},{'id': '122', 'type': 'block', 'children': ['123', '129', '135', '144', '153', '178', '203']},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'new_x'},{'id': '126', 'type': 'binary_operator', 'children': ['127', '128'], 'value': '+'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'new_y'},{'id': '132', 'type': 'binary_operator', 'children': ['133', '134'], 'value': '+'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '135', 'type': 'if_statement', 'children': ['136', '139']},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '138'], 'value': '<'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'new_x'},{'id': '138', 'type': 'integer', 'children': [], 'value': '0'},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'new_x'},{'id': '143', 'type': 'integer', 'children': [], 'value': '0'},{'id': '144', 'type': 'if_statement', 'children': ['145', '148']},{'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': '<'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'new_y'},{'id': '147', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'new_y'},{'id': '152', 'type': 'integer', 'children': [], 'value': '0'},{'id': '153', 'type': 'if_statement', 'children': ['154', '165']},{'id': '154', 'type': 'comparison_operator', 'children': ['155', '156'], 'value': '>'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'new_x'},{'id': '156', 'type': 'binary_operator', 'children': ['157', '164'], 'value': '-'},{'id': '157', 'type': 'call', 'children': ['158', '163']},{'id': '158', 'type': 'attribute', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'grd'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'get_grid_width'},{'id': '163', 'type': 'argument_list', 'children': []},{'id': '164', 'type': 'integer', 'children': [], 'value': '1'},{'id': '165', 'type': 'block', 'children': ['166']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'new_x'},{'id': '169', 'type': 'binary_operator', 'children': ['170', '177'], 'value': '-'},{'id': '170', 'type': 'call', 'children': ['171', '176']},{'id': '171', 'type': 'attribute', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'grd'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'get_grid_width'},{'id': '176', 'type': 'argument_list', 'children': []},{'id': '177', 'type': 'integer', 'children': [], 'value': '1'},{'id': '178', 'type': 'if_statement', 'children': ['179', '190']},{'id': '179', 'type': 'comparison_operator', 'children': ['180', '181'], 'value': '>'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'new_y'},{'id': '181', 'type': 'binary_operator', 'children': ['182', '189'], 'value': '-'},{'id': '182', 'type': 'call', 'children': ['183', '188']},{'id': '183', 'type': 'attribute', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'grd'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'get_grid_height'},{'id': '188', 'type': 'argument_list', 'children': []},{'id': '189', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'new_y'},{'id': '194', 'type': 'binary_operator', 'children': ['195', '202'], 'value': '-'},{'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': 'self'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'grd'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'get_grid_height'},{'id': '201', 'type': 'argument_list', 'children': []},{'id': '202', 'type': 'integer', 'children': [], 'value': '1'},{'id': '203', 'type': 'if_statement', 'children': ['204', '207', '230']},{'id': '204', 'type': 'comparison_operator', 'children': ['205', '206'], 'value': '>'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'expand'},{'id': '206', 'type': 'integer', 'children': [], 'value': '0'},{'id': '207', 'type': 'block', 'children': ['208']},{'id': '208', 'type': 'if_statement', 'children': ['209', '221']},{'id': '209', 'type': 'comparison_operator', 'children': ['210', '217'], 'value': '>'},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'randint'},{'id': '212', 'type': 'argument_list', 'children': ['213', '214']},{'id': '213', 'type': 'integer', 'children': [], 'value': '1'},{'id': '214', 'type': 'binary_operator', 'children': ['215', '216'], 'value': '*'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'expand'},{'id': '216', 'type': 'integer', 'children': [], 'value': '2'},{'id': '217', 'type': '()', 'children': ['218']},{'id': '218', 'type': 'binary_operator', 'children': ['219', '220'], 'value': '+'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'expand'},{'id': '220', 'type': 'integer', 'children': [], 'value': '1'},{'id': '221', 'type': 'block', 'children': ['222']},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '229']},{'id': '224', 'type': 'subscript', 'children': ['225', '228']},{'id': '225', 'type': 'subscript', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'updated_grid'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'new_y'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'new_x'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '230', 'type': 'else_clause', 'children': ['231']},{'id': '231', 'type': 'block', 'children': ['232']},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '239']},{'id': '234', 'type': 'subscript', 'children': ['235', '238']},{'id': '235', 'type': 'subscript', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'updated_grid'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'new_y'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'new_x'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'call', 'children': ['242', '247']},{'id': '242', 'type': 'attribute', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'grd'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'replace_grid'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'updated_grid'}
def denoise_grid(self, val, expand=1): updated_grid = [[self.grd.get_tile(y,x) \ for x in range(self.grd.grid_width)] \ for y in range(self.grd.grid_height)] for row in range(self.grd.get_grid_height() - expand): for col in range(self.grd.get_grid_width() - expand): updated_grid[row][col] = self.grd.get_tile(row,col) if self.grd.get_tile(row,col) == val: for y in range(-expand, expand): for x in range(-expand, expand): new_x = col+x new_y = row+y if new_x < 0: new_x = 0 if new_y < 0: new_y = 0 if new_x > self.grd.get_grid_width() - 1: new_x = self.grd.get_grid_width() - 1 if new_y > self.grd.get_grid_height() - 1: new_y = self.grd.get_grid_height() - 1 if expand > 0: if randint(1,expand * 2) > (expand+1): updated_grid[new_y][new_x] = val else: updated_grid[new_y][new_x] = val self.grd.replace_grid(updated_grid)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'run'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'num_runs'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'show_trails'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'log_file_base'},{'id': '8', 'type': 'block', 'children': ['9', '14', '33', '58', '78', '84', '131', '268']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'string', 'children': [], 'value': '"--------------------------------------------------"'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19', '26']},{'id': '18', 'type': 'string', 'children': [], 'value': '"Starting Simulation - target = "'},{'id': '19', 'type': 'attribute', 'children': ['20', '25']},{'id': '20', 'type': 'subscript', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '24', 'type': 'integer', 'children': [], 'value': '0'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'target_y'},{'id': '26', 'type': 'attribute', 'children': ['27', '32']},{'id': '27', 'type': 'subscript', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '31', 'type': 'integer', 'children': [], 'value': '0'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'target_x'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '42']},{'id': '35', 'type': 'attribute', 'children': ['36', '41']},{'id': '36', 'type': 'attribute', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'world'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'grd'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'set_tile'},{'id': '42', 'type': 'argument_list', 'children': ['43', '50', '57']},{'id': '43', 'type': 'attribute', 'children': ['44', '49']},{'id': '44', 'type': 'subscript', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '48', 'type': 'integer', 'children': [], 'value': '0'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'target_y'},{'id': '50', 'type': 'attribute', 'children': ['51', '56']},{'id': '51', 'type': 'subscript', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '55', 'type': 'integer', 'children': [], 'value': '0'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'target_x'},{'id': '57', 'type': 'string', 'children': [], 'value': "'T'"},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'highlight_cell_surroundings'},{'id': '63', 'type': 'argument_list', 'children': ['64', '71']},{'id': '64', 'type': 'attribute', 'children': ['65', '70']},{'id': '65', 'type': 'subscript', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '69', 'type': 'integer', 'children': [], 'value': '0'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'target_y'},{'id': '71', 'type': 'attribute', 'children': ['72', '77']},{'id': '72', 'type': 'subscript', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '76', 'type': 'integer', 'children': [], 'value': '0'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'target_x'},{'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': 'start_all_agents'},{'id': '83', 'type': 'argument_list', 'children': []},{'id': '84', 'type': 'try_statement', 'children': ['85', '121']},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'with_statement', 'children': ['87', '99']},{'id': '87', 'type': 'with_clause', 'children': ['88']},{'id': '88', 'type': 'with_item', 'children': ['89']},{'id': '89', 'type': 'as_pattern', 'children': ['90', '97']},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '92', 'type': 'argument_list', 'children': ['93', '96']},{'id': '93', 'type': 'binary_operator', 'children': ['94', '95'], 'value': '+'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'log_file_base'},{'id': '95', 'type': 'string', 'children': [], 'value': "'__agents.txt'"},{'id': '96', 'type': 'string', 'children': [], 'value': '"w"'},{'id': '97', 'type': 'as_pattern_target', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '99', 'type': 'block', 'children': ['100', '107']},{'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': 'f'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'string', 'children': [], 'value': '"Starting World = \\n"'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'attribute', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'world'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'grd'},{'id': '121', 'type': 'except_clause', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '123', 'type': 'block', 'children': ['124']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'binary_operator', 'children': ['129', '130'], 'value': '+'},{'id': '129', 'type': 'string', 'children': [], 'value': "'Cant save log results to '"},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'log_file_base'},{'id': '131', 'type': 'for_statement', 'children': ['132', '133', '138']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'cur_run'},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '135', 'type': 'argument_list', 'children': ['136', '137']},{'id': '136', 'type': 'integer', 'children': [], 'value': '0'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'num_runs'},{'id': '138', 'type': 'block', 'children': ['139', '146', '243']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142', '144']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '142', 'type': 'ERROR', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'WorldSimulation'},{'id': '144', 'type': 'type', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '146', 'type': 'for_statement', 'children': ['147', '150', '156']},{'id': '147', 'type': 'pattern_list', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'agt'},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '156', 'type': 'block', 'children': ['157', '220', '226']},{'id': '157', 'type': 'if_statement', 'children': ['158', '161']},{'id': '158', 'type': 'comparison_operator', 'children': ['159', '160'], 'value': '=='},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'show_trails'},{'id': '160', 'type': 'string', 'children': [], 'value': "'Y'"},{'id': '161', 'type': 'block', 'children': ['162']},{'id': '162', 'type': 'if_statement', 'children': ['163', '180', '198']},{'id': '163', 'type': 'boolean_operator', 'children': ['164', '172'], 'value': 'or'},{'id': '164', 'type': 'comparison_operator', 'children': ['165', '171'], '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': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '171', 'type': 'integer', 'children': [], 'value': '1'},{'id': '172', 'type': 'comparison_operator', 'children': ['173', '179'], 'value': '>'},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '179', 'type': 'integer', 'children': [], 'value': '9'},{'id': '180', 'type': 'block', 'children': ['181']},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'call', 'children': ['183', '190']},{'id': '183', 'type': 'attribute', 'children': ['184', '189']},{'id': '184', 'type': 'attribute', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'world'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'grd'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'set_tile'},{'id': '190', 'type': 'argument_list', 'children': ['191', '194', '197']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'agt'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'current_y'},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'agt'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'current_x'},{'id': '197', 'type': 'string', 'children': [], 'value': "'o'"},{'id': '198', 'type': 'else_clause', 'children': ['199']},{'id': '199', 'type': 'block', 'children': ['200']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '209']},{'id': '202', 'type': 'attribute', 'children': ['203', '208']},{'id': '203', 'type': 'attribute', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'world'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'grd'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'set_tile'},{'id': '209', 'type': 'argument_list', 'children': ['210', '213', '216']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'agt'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'current_y'},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'agt'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'current_x'},{'id': '216', 'type': 'call', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'num'},{'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': 'agt'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'do_your_job'},{'id': '225', 'type': 'argument_list', 'children': []},{'id': '226', 'type': 'expression_statement', 'children': ['227']},{'id': '227', 'type': 'call', 'children': ['228', '235']},{'id': '228', 'type': 'attribute', 'children': ['229', '234']},{'id': '229', 'type': 'attribute', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'world'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'grd'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'set_tile'},{'id': '235', 'type': 'argument_list', 'children': ['236', '239', '242']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'agt'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'current_y'},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'agt'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'current_x'},{'id': '242', 'type': 'string', 'children': [], 'value': "'A'"},{'id': '243', 'type': 'if_statement', 'children': ['244', '247']},{'id': '244', 'type': 'comparison_operator', 'children': ['245', '246'], 'value': '!='},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'log_file_base'},{'id': '246', 'type': 'string', 'children': [], 'value': "'N'"},{'id': '247', 'type': 'block', 'children': ['248']},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'call', 'children': ['250', '257']},{'id': '250', 'type': 'attribute', 'children': ['251', '256']},{'id': '251', 'type': 'attribute', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'world'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'grd'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'save'},{'id': '257', 'type': 'argument_list', 'children': ['258']},{'id': '258', 'type': 'binary_operator', 'children': ['259', '267'], 'value': '+'},{'id': '259', 'type': 'binary_operator', 'children': ['260', '263'], 'value': '+'},{'id': '260', 'type': 'binary_operator', 'children': ['261', '262'], 'value': '+'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'log_file_base'},{'id': '262', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '263', 'type': 'call', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '265', 'type': 'argument_list', 'children': ['266']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'cur_run'},{'id': '267', 'type': 'string', 'children': [], 'value': "'.log'"},{'id': '268', 'type': 'with_statement', 'children': ['269', '281']},{'id': '269', 'type': 'with_clause', 'children': ['270']},{'id': '270', 'type': 'with_item', 'children': ['271']},{'id': '271', 'type': 'as_pattern', 'children': ['272', '279']},{'id': '272', 'type': 'call', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '274', 'type': 'argument_list', 'children': ['275', '278']},{'id': '275', 'type': 'binary_operator', 'children': ['276', '277'], 'value': '+'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'log_file_base'},{'id': '277', 'type': 'string', 'children': [], 'value': "'__agents.txt'"},{'id': '278', 'type': 'string', 'children': [], 'value': '"a"'},{'id': '279', 'type': 'as_pattern_target', 'children': ['280']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '281', 'type': 'block', 'children': ['282', '315', '329', '336']},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'call', 'children': ['284', '287']},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '287', 'type': 'argument_list', 'children': ['288']},{'id': '288', 'type': 'binary_operator', 'children': ['289', '314'], 'value': '+'},{'id': '289', 'type': 'binary_operator', 'children': ['290', '304'], 'value': '+'},{'id': '290', 'type': 'binary_operator', 'children': ['291', '303'], 'value': '+'},{'id': '291', 'type': 'binary_operator', 'children': ['292', '293'], 'value': '+'},{'id': '292', 'type': 'string', 'children': [], 'value': '"\\nWorld tgt= ["'},{'id': '293', 'type': 'call', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '295', 'type': 'argument_list', 'children': ['296']},{'id': '296', 'type': 'attribute', 'children': ['297', '302']},{'id': '297', 'type': 'subscript', 'children': ['298', '301']},{'id': '298', 'type': 'attribute', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '301', 'type': 'integer', 'children': [], 'value': '0'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'target_y'},{'id': '303', 'type': 'string', 'children': [], 'value': '","'},{'id': '304', 'type': 'call', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '306', 'type': 'argument_list', 'children': ['307']},{'id': '307', 'type': 'attribute', 'children': ['308', '313']},{'id': '308', 'type': 'subscript', 'children': ['309', '312']},{'id': '309', 'type': 'attribute', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '312', 'type': 'integer', 'children': [], 'value': '0'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'target_x'},{'id': '314', 'type': 'string', 'children': [], 'value': '"]\\n"'},{'id': '315', 'type': 'expression_statement', 'children': ['316']},{'id': '316', 'type': 'call', 'children': ['317', '320']},{'id': '317', 'type': 'attribute', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '320', 'type': 'argument_list', 'children': ['321']},{'id': '321', 'type': 'call', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '323', 'type': 'argument_list', 'children': ['324']},{'id': '324', 'type': 'attribute', 'children': ['325', '328']},{'id': '325', 'type': 'attribute', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'world'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'grd'},{'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': 'f'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '334', 'type': 'argument_list', 'children': ['335']},{'id': '335', 'type': 'string', 'children': [], 'value': "'\\n\\nAgent Name , starting, num Steps , num Climbs\\n'"},{'id': '336', 'type': 'for_statement', 'children': ['337', '340', '346']},{'id': '337', 'type': 'pattern_list', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'agt'},{'id': '340', 'type': 'call', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '342', 'type': 'argument_list', 'children': ['343']},{'id': '343', 'type': 'attribute', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'agent_list'},{'id': '346', 'type': 'block', 'children': ['347', '373', '393', '408']},{'id': '347', 'type': 'expression_statement', 'children': ['348']},{'id': '348', 'type': 'assignment', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '350', 'type': 'binary_operator', 'children': ['351', '372'], 'value': '+'},{'id': '351', 'type': 'binary_operator', 'children': ['352', '366'], 'value': '+'},{'id': '352', 'type': 'binary_operator', 'children': ['353', '365'], 'value': '+'},{'id': '353', 'type': 'binary_operator', 'children': ['354', '359'], 'value': '+'},{'id': '354', 'type': 'binary_operator', 'children': ['355', '358'], 'value': '+'},{'id': '355', 'type': 'attribute', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'agt'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '358', 'type': 'string', 'children': [], 'value': "' , ['"},{'id': '359', 'type': 'call', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '361', 'type': 'argument_list', 'children': ['362']},{'id': '362', 'type': 'attribute', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'agt'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'start_y'},{'id': '365', 'type': 'string', 'children': [], 'value': "', '"},{'id': '366', 'type': 'call', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '368', 'type': 'argument_list', 'children': ['369']},{'id': '369', 'type': 'attribute', 'children': ['370', '371']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'agt'},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'start_x'},{'id': '372', 'type': 'string', 'children': [], 'value': "'], '"},{'id': '373', 'type': 'expression_statement', 'children': ['374']},{'id': '374', 'type': 'augmented_assignment', 'children': ['375', '376'], 'value': '+='},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '376', 'type': 'binary_operator', 'children': ['377', '392'], 'value': '+'},{'id': '377', 'type': 'binary_operator', 'children': ['378', '386'], 'value': '+'},{'id': '378', 'type': 'binary_operator', 'children': ['379', '385'], 'value': '+'},{'id': '379', 'type': 'call', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '381', 'type': 'argument_list', 'children': ['382']},{'id': '382', 'type': 'attribute', 'children': ['383', '384']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'agt'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'num_steps'},{'id': '385', 'type': 'string', 'children': [], 'value': "' , '"},{'id': '386', 'type': 'call', 'children': ['387', '388']},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '388', 'type': 'argument_list', 'children': ['389']},{'id': '389', 'type': 'attribute', 'children': ['390', '391']},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'agt'},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'num_climbs'},{'id': '392', 'type': 'string', 'children': [], 'value': "' , '"},{'id': '393', 'type': 'expression_statement', 'children': ['394']},{'id': '394', 'type': 'augmented_assignment', 'children': ['395', '396'], 'value': '+='},{'id': '395', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '396', 'type': 'call', 'children': ['397', '400']},{'id': '397', 'type': 'attribute', 'children': ['398', '399']},{'id': '398', 'type': 'string', 'children': [], 'value': "''"},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '400', 'type': 'argument_list', 'children': ['401']},{'id': '401', 'type': 'list_comprehension', 'children': ['402', '403']},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '403', 'type': 'for_in_clause', 'children': ['404', '405']},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '405', 'type': 'attribute', 'children': ['406', '407']},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'agt'},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '408', 'type': 'expression_statement', 'children': ['409']},{'id': '409', 'type': 'call', 'children': ['410', '413']},{'id': '410', 'type': 'attribute', 'children': ['411', '412']},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '412', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '413', 'type': 'argument_list', 'children': ['414']},{'id': '414', 'type': 'binary_operator', 'children': ['415', '416'], 'value': '+'},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '416', 'type': 'string', 'children': [], 'value': "'\\n'"}
def run(self, num_runs, show_trails, log_file_base): print("--------------------------------------------------") print("Starting Simulation - target = ", self.agent_list[0].target_y, self.agent_list[0].target_x) self.world.grd.set_tile(self.agent_list[0].target_y , self.agent_list[0].target_x , 'T') self.highlight_cell_surroundings(self.agent_list[0].target_y, self.agent_list[0].target_x) self.start_all_agents() try: with open (log_file_base + '__agents.txt', "w") as f: f.write("Starting World = \n") f.write(str(self.world.grd)) except Exception: print('Cant save log results to ' + log_file_base) for cur_run in range(0,num_runs): print("WorldSimulation:run for num, agt in enumerate(self.agent_list): if show_trails == 'Y': if len(self.agent_list) == 1 or len(self.agent_list) > 9: self.world.grd.set_tile(agt.current_y, agt.current_x, 'o') else: self.world.grd.set_tile(agt.current_y, agt.current_x, str(num)) agt.do_your_job() self.world.grd.set_tile(agt.current_y, agt.current_x, 'A') if log_file_base != 'N': self.world.grd.save(log_file_base + '_' + str(cur_run) + '.log') with open (log_file_base + '__agents.txt', "a") as f: f.write("\nWorld tgt= [" + str(self.agent_list[0].target_y) + "," + str(self.agent_list[0].target_x) + "]\n") f.write(str(self.world.grd)) f.write('\n\nAgent Name , starting, num Steps , num Climbs\n') for num, agt in enumerate(self.agent_list): res = agt.name + ' , [' + str(agt.start_y) + ', ' + str(agt.start_x) + '], ' res += str(agt.num_steps) + ' , ' + str(agt.num_climbs) + ' , ' res += ''.join([a for a in agt.results]) f.write(res + '\n')
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'rest'},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '9', 'type': 'block', 'children': ['10', '19', '25', '37', '41', '71']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'ensure_keyword_args'},{'id': '13', 'type': 'argument_list', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '15', 'type': 'keyword_argument', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'optional'},{'id': '17', 'type': 'tuple', 'children': ['18']},{'id': '18', 'type': 'string', 'children': [], 'value': "'default'"},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'has_default'},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'in'},{'id': '23', 'type': 'string', 'children': [], 'value': "'default'"},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '25', 'type': 'if_statement', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'has_default'},{'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': 'default'},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'ensure_callable'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'subscript', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '36', 'type': 'string', 'children': [], 'value': "'default'"},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'unary_result'},{'id': '40', 'type': 'True', 'children': []},{'id': '41', 'type': 'if_statement', 'children': ['42', '43', '65']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'rest'},{'id': '43', 'type': 'block', 'children': ['44', '61']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'fs'},{'id': '47', 'type': 'binary_operator', 'children': ['48', '53'], 'value': '+'},{'id': '48', 'type': 'tuple', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'ensure_callable'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'imap'},{'id': '58', 'type': 'argument_list', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'ensure_callable'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'rest'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'unary_result'},{'id': '64', 'type': 'False', 'children': []},{'id': '65', 'type': 'else_clause', 'children': ['66']},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'fs'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '71', 'type': 'if_statement', 'children': ['72', '76', '130']},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'is_mapping'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'fs'},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'if_statement', 'children': ['78', '79', '106']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'has_default'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'return_statement', 'children': ['81']},{'id': '81', 'type': 'lambda', 'children': ['82', '84']},{'id': '82', 'type': 'lambda_parameters', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'arg_'},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'fs'},{'id': '87', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '88', 'type': 'generator_expression', 'children': ['89', '103']},{'id': '89', 'type': 'tuple', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '91', 'type': 'call', 'children': ['92', '99']},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'fs'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '96', 'type': 'argument_list', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'subscript', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'arg_'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '103', 'type': 'for_in_clause', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'arg_'},{'id': '106', 'type': 'else_clause', 'children': ['107']},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'return_statement', 'children': ['109']},{'id': '109', 'type': 'lambda', 'children': ['110', '112']},{'id': '110', 'type': 'lambda_parameters', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'arg_'},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'fs'},{'id': '115', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '116', 'type': 'generator_expression', 'children': ['117', '127']},{'id': '117', 'type': 'tuple', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'subscript', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'fs'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'subscript', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'arg_'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '127', 'type': 'for_in_clause', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'arg_'},{'id': '130', 'type': 'else_clause', 'children': ['131']},{'id': '131', 'type': 'block', 'children': ['132', '137', '201']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'ensure_sequence'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'fs'},{'id': '137', 'type': 'if_statement', 'children': ['138', '139', '174']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'has_default'},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '143', 'type': 'lambda', 'children': ['144', '146']},{'id': '144', 'type': 'lambda_parameters', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'arg_'},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'fs'},{'id': '149', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '150', 'type': 'generator_expression', 'children': ['151', '166']},{'id': '151', 'type': 'call', 'children': ['152', '164']},{'id': '152', 'type': '()', 'children': ['153']},{'id': '153', 'type': 'conditional_expression', 'children': ['154', '157', '163'], 'value': 'if'},{'id': '154', 'type': 'subscript', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'fs'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '157', 'type': 'comparison_operator', 'children': ['158', '159'], 'value': '<'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'fs'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '166', 'type': 'for_in_clause', 'children': ['167', '170']},{'id': '167', 'type': 'pattern_list', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '170', 'type': 'call', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'arg_'},{'id': '174', 'type': 'else_clause', 'children': ['175']},{'id': '175', 'type': 'block', 'children': ['176']},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '179', 'type': 'lambda', 'children': ['180', '182']},{'id': '180', 'type': 'lambda_parameters', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'arg_'},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'fs'},{'id': '185', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '186', 'type': 'generator_expression', 'children': ['187', '193']},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'subscript', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'fs'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '193', 'type': 'for_in_clause', 'children': ['194', '197']},{'id': '194', 'type': 'pattern_list', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '197', 'type': 'call', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'arg_'},{'id': '201', 'type': 'return_statement', 'children': ['202']},{'id': '202', 'type': 'conditional_expression', 'children': ['203', '204', '205'], 'value': 'if'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'unary_result'},{'id': '205', 'type': 'lambda', 'children': ['206', '209']},{'id': '206', 'type': 'lambda_parameters', 'children': ['207']},{'id': '207', 'type': 'list_splat_pattern', 'children': ['208']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '209', 'type': 'call', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'args'}
def merge(arg, *rest, **kwargs): ensure_keyword_args(kwargs, optional=('default',)) has_default = 'default' in kwargs if has_default: default = ensure_callable(kwargs['default']) unary_result = True if rest: fs = (ensure_callable(arg),) + tuple(imap(ensure_callable, rest)) unary_result = False else: fs = arg if is_mapping(fs): if has_default: return lambda arg_: fs.__class__((k, fs.get(k, default)(arg_[k])) for k in arg_) else: return lambda arg_: fs.__class__((k, fs[k](arg_[k])) for k in arg_) else: ensure_sequence(fs) if has_default: func = lambda arg_: fs.__class__( (fs[i] if i < len(fs) else default)(x) for i, x in enumerate(arg_)) else: func = lambda arg_: fs.__class__(fs[i](x) for i, x in enumerate(arg_)) return func if unary_result else lambda *args: func(args)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'cmd'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '7', 'type': 'block', 'children': ['8', '27', '33', '44', '52', '62', '72', '87', '115']},{'id': '8', 'type': 'if_statement', 'children': ['9', '20']},{'id': '9', 'type': 'not_operator', 'children': ['10']},{'id': '10', 'type': 'call', 'children': ['11', '18']},{'id': '11', 'type': 'attribute', 'children': ['12', '17']},{'id': '12', 'type': 'subscript', 'children': ['13', '16']},{'id': '13', 'type': 'subscript', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '15', 'type': 'string', 'children': [], 'value': "'config'"},{'id': '16', 'type': 'string', 'children': [], 'value': "'feature'"},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'getboolean'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'string', 'children': [], 'value': "'hooks'"},{'id': '20', 'type': 'block', 'children': ['21', '26']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'string', 'children': [], 'value': '"Hooks are disabled, and this command depends on hooks. Please contact the bot admin(s)."'},{'id': '26', 'type': 'return_statement', 'children': []},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '30', 'type': 'subscript', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '32', 'type': 'string', 'children': [], 'value': "'db'"},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'arguments'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'ArgParser'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '43', 'type': 'string', 'children': [], 'value': "'config'"},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'add_mutually_exclusive_group'},{'id': '51', 'type': 'argument_list', 'children': []},{'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': 'group'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59']},{'id': '58', 'type': 'string', 'children': [], 'value': "'--high'"},{'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '61', 'type': 'string', 'children': [], 'value': "'store_true'"},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '67', 'type': 'argument_list', 'children': ['68', '69']},{'id': '68', 'type': 'string', 'children': [], 'value': "'--low'"},{'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '71', 'type': 'string', 'children': [], 'value': "'store_true'"},{'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': 'group'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '77', 'type': 'argument_list', 'children': ['78', '79', '82']},{'id': '78', 'type': 'string', 'children': [], 'value': "'nick'"},{'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'nargs'},{'id': '81', 'type': 'string', 'children': [], 'value': "'?'"},{'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'arguments'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'NickParser'},{'id': '87', 'type': 'try_statement', 'children': ['88', '98']},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'cmdargs'},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'parse_args'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '98', 'type': 'except_clause', 'children': ['99', '105']},{'id': '99', 'type': 'as_pattern', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'arguments'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'ArgumentException'},{'id': '103', 'type': 'as_pattern_target', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '105', 'type': 'block', 'children': ['106', '114']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '114', 'type': 'return_statement', 'children': []},{'id': '115', 'type': 'if_statement', 'children': ['116', '119', '171', '223', '359']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'cmdargs'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'high'},{'id': '119', 'type': 'block', 'children': ['120', '149', '154']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '123', 'type': 'call', 'children': ['124', '148']},{'id': '124', 'type': 'attribute', 'children': ['125', '147']},{'id': '125', 'type': 'call', 'children': ['126', '145']},{'id': '126', 'type': 'attribute', 'children': ['127', '144']},{'id': '127', 'type': 'call', 'children': ['128', '136']},{'id': '128', 'type': 'attribute', 'children': ['129', '135']},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'Scores'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'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': 'Scores'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '143', 'type': 'argument_list', 'children': []},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'integer', 'children': [], 'value': '3'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '148', 'type': 'argument_list', 'children': []},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'string', 'children': [], 'value': "'High Scores:'"},{'id': '154', 'type': 'for_statement', 'children': ['155', '156', '157']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '157', 'type': 'block', 'children': ['158']},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'binary_operator', 'children': ['163', '164'], 'value': '%'},{'id': '163', 'type': 'string', 'children': [], 'value': '"%s: %s"'},{'id': '164', 'type': 'tuple', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '171', 'type': 'elif_clause', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'cmdargs'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'low'},{'id': '175', 'type': 'block', 'children': ['176', '201', '206']},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '179', 'type': 'call', 'children': ['180', '200']},{'id': '180', 'type': 'attribute', 'children': ['181', '199']},{'id': '181', 'type': 'call', 'children': ['182', '197']},{'id': '182', 'type': 'attribute', 'children': ['183', '196']},{'id': '183', 'type': 'call', 'children': ['184', '192']},{'id': '184', 'type': 'attribute', 'children': ['185', '191']},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'Scores'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'Scores'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'integer', 'children': [], 'value': '3'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '200', 'type': 'argument_list', 'children': []},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'string', 'children': [], 'value': "'Low Scores:'"},{'id': '206', 'type': 'for_statement', 'children': ['207', '208', '209']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'data'},{'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': 'send'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'binary_operator', 'children': ['215', '216'], 'value': '%'},{'id': '215', 'type': 'string', 'children': [], 'value': '"%s: %s"'},{'id': '216', 'type': 'tuple', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '223', 'type': 'elif_clause', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'cmdargs'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '227', 'type': 'block', 'children': ['228', '238', '249', '271']},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '231', 'type': 'call', 'children': ['232', '237']},{'id': '232', 'type': 'attribute', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'cmdargs'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '237', 'type': 'argument_list', 'children': []},{'id': '238', 'type': 'if_statement', 'children': ['239', '242']},{'id': '239', 'type': 'comparison_operator', 'children': ['240', '241'], 'value': '=='},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '241', 'type': 'string', 'children': [], 'value': "'c'"},{'id': '242', 'type': 'block', 'children': ['243', '248']},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'call', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'string', 'children': [], 'value': '"We all know you love C better than anything else, so why rub it in?"'},{'id': '248', 'type': 'return_statement', 'children': []},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'assignment', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '252', 'type': 'call', 'children': ['253', '270']},{'id': '253', 'type': 'attribute', 'children': ['254', '269']},{'id': '254', 'type': 'call', 'children': ['255', '263']},{'id': '255', 'type': 'attribute', 'children': ['256', '262']},{'id': '256', 'type': 'call', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '260', 'type': 'argument_list', 'children': ['261']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'Scores'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '263', 'type': 'argument_list', 'children': ['264']},{'id': '264', 'type': 'comparison_operator', 'children': ['265', '268'], 'value': '=='},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'Scores'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'scalar'},{'id': '270', 'type': 'argument_list', 'children': []},{'id': '271', 'type': 'if_statement', 'children': ['272', '275', '350']},{'id': '272', 'type': 'comparison_operator', 'children': ['273', '274'], 'value': 'is'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '274', 'type': 'None', 'children': []},{'id': '275', 'type': 'block', 'children': ['276', '290']},{'id': '276', 'type': 'expression_statement', 'children': ['277']},{'id': '277', 'type': 'assignment', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'plural'},{'id': '279', 'type': 'conditional_expression', 'children': ['280', '281', '289'], 'value': 'if'},{'id': '280', 'type': 'string', 'children': [], 'value': "''"},{'id': '281', 'type': 'comparison_operator', 'children': ['282', '288'], 'value': '=='},{'id': '282', 'type': 'call', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '284', 'type': 'argument_list', 'children': ['285']},{'id': '285', 'type': 'attribute', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '288', 'type': 'integer', 'children': [], 'value': '1'},{'id': '289', 'type': 'string', 'children': [], 'value': "'s'"},{'id': '290', 'type': 'if_statement', 'children': ['291', '300', '336']},{'id': '291', 'type': 'comparison_operator', 'children': ['292', '293'], 'value': '=='},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '293', 'type': 'call', 'children': ['294', '299']},{'id': '294', 'type': 'attribute', 'children': ['295', '298']},{'id': '295', 'type': 'subscript', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '297', 'type': 'string', 'children': [], 'value': "'botnick'"},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '299', 'type': 'argument_list', 'children': []},{'id': '300', 'type': 'block', 'children': ['301', '319', '330']},{'id': '301', 'type': 'expression_statement', 'children': ['302']},{'id': '302', 'type': 'assignment', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'emote'},{'id': '304', 'type': 'conditional_expression', 'children': ['305', '306', '311'], 'value': 'if'},{'id': '305', 'type': 'string', 'children': [], 'value': "':)'"},{'id': '306', 'type': 'comparison_operator', 'children': ['307', '310'], 'value': '>'},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '310', 'type': 'integer', 'children': [], 'value': '0'},{'id': '311', 'type': 'conditional_expression', 'children': ['312', '313', '318'], 'value': 'if'},{'id': '312', 'type': 'string', 'children': [], 'value': "':('"},{'id': '313', 'type': 'comparison_operator', 'children': ['314', '317'], 'value': '<'},{'id': '314', 'type': 'attribute', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '317', 'type': 'integer', 'children': [], 'value': '0'},{'id': '318', 'type': 'string', 'children': [], 'value': "':|'"},{'id': '319', 'type': 'expression_statement', 'children': ['320']},{'id': '320', 'type': 'assignment', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '322', 'type': 'binary_operator', 'children': ['323', '324'], 'value': '%'},{'id': '323', 'type': 'string', 'children': [], 'value': "'has %s point%s! %s'"},{'id': '324', 'type': 'tuple', 'children': ['325', '328', '329']},{'id': '325', 'type': 'attribute', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'plural'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'emote'},{'id': '330', 'type': 'expression_statement', 'children': ['331']},{'id': '331', 'type': 'call', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '333', 'type': 'argument_list', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '335', 'type': 'string', 'children': [], 'value': "'action'"},{'id': '336', 'type': 'else_clause', 'children': ['337']},{'id': '337', 'type': 'block', 'children': ['338']},{'id': '338', 'type': 'expression_statement', 'children': ['339']},{'id': '339', 'type': 'call', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '341', 'type': 'argument_list', 'children': ['342']},{'id': '342', 'type': 'binary_operator', 'children': ['343', '344'], 'value': '%'},{'id': '343', 'type': 'string', 'children': [], 'value': '"%s has %i point%s!"'},{'id': '344', 'type': 'tuple', 'children': ['345', '346', '349']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '346', 'type': 'attribute', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'plural'},{'id': '350', 'type': 'else_clause', 'children': ['351']},{'id': '351', 'type': 'block', 'children': ['352']},{'id': '352', 'type': 'expression_statement', 'children': ['353']},{'id': '353', 'type': 'call', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '355', 'type': 'argument_list', 'children': ['356']},{'id': '356', 'type': 'binary_operator', 'children': ['357', '358'], 'value': '%'},{'id': '357', 'type': 'string', 'children': [], 'value': '"Nobody cares about %s"'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '359', 'type': 'else_clause', 'children': ['360']},{'id': '360', 'type': 'block', 'children': ['361']},{'id': '361', 'type': 'if_statement', 'children': ['362', '374', '380']},{'id': '362', 'type': 'comparison_operator', 'children': ['363', '373'], 'value': '=='},{'id': '363', 'type': 'call', 'children': ['364', '372']},{'id': '364', 'type': 'attribute', 'children': ['365', '371']},{'id': '365', 'type': 'call', 'children': ['366', '369']},{'id': '366', 'type': 'attribute', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '369', 'type': 'argument_list', 'children': ['370']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'Scores'},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '372', 'type': 'argument_list', 'children': []},{'id': '373', 'type': 'integer', 'children': [], 'value': '0'},{'id': '374', 'type': 'block', 'children': ['375']},{'id': '375', 'type': 'expression_statement', 'children': ['376']},{'id': '376', 'type': 'call', 'children': ['377', '378']},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '378', 'type': 'argument_list', 'children': ['379']},{'id': '379', 'type': 'string', 'children': [], 'value': '"Nobody cares about anything =("'},{'id': '380', 'type': 'else_clause', 'children': ['381']},{'id': '381', 'type': 'block', 'children': ['382', '404', '418']},{'id': '382', 'type': 'expression_statement', 'children': ['383']},{'id': '383', 'type': 'assignment', 'children': ['384', '385']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '385', 'type': 'call', 'children': ['386', '403']},{'id': '386', 'type': 'attribute', 'children': ['387', '402']},{'id': '387', 'type': 'call', 'children': ['388', '396']},{'id': '388', 'type': 'attribute', 'children': ['389', '395']},{'id': '389', 'type': 'call', 'children': ['390', '393']},{'id': '390', 'type': 'attribute', 'children': ['391', '392']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '393', 'type': 'argument_list', 'children': ['394']},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'Scores'},{'id': '395', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '396', 'type': 'argument_list', 'children': ['397']},{'id': '397', 'type': 'call', 'children': ['398', '401']},{'id': '398', 'type': 'attribute', 'children': ['399', '400']},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '401', 'type': 'argument_list', 'children': []},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '403', 'type': 'argument_list', 'children': []},{'id': '404', 'type': 'expression_statement', 'children': ['405']},{'id': '405', 'type': 'assignment', 'children': ['406', '407']},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'plural'},{'id': '407', 'type': 'conditional_expression', 'children': ['408', '409', '417'], 'value': 'if'},{'id': '408', 'type': 'string', 'children': [], 'value': "''"},{'id': '409', 'type': 'comparison_operator', 'children': ['410', '416'], 'value': '=='},{'id': '410', 'type': 'call', 'children': ['411', '412']},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '412', 'type': 'argument_list', 'children': ['413']},{'id': '413', 'type': 'attribute', 'children': ['414', '415']},{'id': '414', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '416', 'type': 'integer', 'children': [], 'value': '1'},{'id': '417', 'type': 'string', 'children': [], 'value': "'s'"},{'id': '418', 'type': 'expression_statement', 'children': ['419']},{'id': '419', 'type': 'call', 'children': ['420', '421']},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '421', 'type': 'argument_list', 'children': ['422']},{'id': '422', 'type': 'binary_operator', 'children': ['423', '424'], 'value': '%'},{'id': '423', 'type': 'string', 'children': [], 'value': '"%s has %i point%s!"'},{'id': '424', 'type': 'tuple', 'children': ['425', '428', '431']},{'id': '425', 'type': 'attribute', 'children': ['426', '427']},{'id': '426', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '427', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '428', 'type': 'attribute', 'children': ['429', '430']},{'id': '429', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '430', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '431', 'type': 'identifier', 'children': [], 'value': 'plural'}
def cmd(send, msg, args): if not args['config']['feature'].getboolean('hooks'): send("Hooks are disabled, and this command depends on hooks. Please contact the bot admin(s).") return session = args['db'] parser = arguments.ArgParser(args['config']) group = parser.add_mutually_exclusive_group() group.add_argument('--high', action='store_true') group.add_argument('--low', action='store_true') group.add_argument('nick', nargs='?', action=arguments.NickParser) try: cmdargs = parser.parse_args(msg) except arguments.ArgumentException as e: send(str(e)) return if cmdargs.high: data = session.query(Scores).order_by(Scores.score.desc()).limit(3).all() send('High Scores:') for x in data: send("%s: %s" % (x.nick, x.score)) elif cmdargs.low: data = session.query(Scores).order_by(Scores.score).limit(3).all() send('Low Scores:') for x in data: send("%s: %s" % (x.nick, x.score)) elif cmdargs.nick: name = cmdargs.nick.lower() if name == 'c': send("We all know you love C better than anything else, so why rub it in?") return score = session.query(Scores).filter(Scores.nick == name).scalar() if score is not None: plural = '' if abs(score.score) == 1 else 's' if name == args['botnick'].lower(): emote = ':)' if score.score > 0 else ':(' if score.score < 0 else ':|' output = 'has %s point%s! %s' % (score.score, plural, emote) send(output, 'action') else: send("%s has %i point%s!" % (name, score.score, plural)) else: send("Nobody cares about %s" % name) else: if session.query(Scores).count() == 0: send("Nobody cares about anything =(") else: query = session.query(Scores).order_by(func.random()).first() plural = '' if abs(query.score) == 1 else 's' send("%s has %i point%s!" % (query.nick, query.score, plural))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'buildPrices'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'roles'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'regex'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'default_price_regex'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'additional'},{'id': '16', 'type': 'dictionary', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '20']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'string', 'children': [], 'value': "''' Create a dictionary with price information. Multiple ways are\n supported.\n :rtype: :obj:`dict`: keys are role as str, values are the prices as\n cent count'''"},{'id': '20', 'type': 'if_statement', 'children': ['21', '26', '63', '142', '184']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '26', 'type': 'block', 'children': ['27', '48']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '30', 'type': 'list_comprehension', 'children': ['31', '41']},{'id': '31', 'type': 'tuple', 'children': ['32', '35']},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '34', 'type': 'integer', 'children': [], 'value': '0'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'convertPrice'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'subscript', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '40', 'type': 'integer', 'children': [], 'value': '1'},{'id': '41', 'type': 'for_in_clause', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'item'},{'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': 'items'},{'id': '47', 'type': 'argument_list', 'children': []},{'id': '48', 'type': 'return_statement', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'list_comprehension', 'children': ['53', '54', '57']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '54', 'type': 'for_in_clause', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '57', 'type': 'if_clause', 'children': ['58']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '62'], 'value': 'is'},{'id': '59', 'type': 'subscript', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '61', 'type': 'integer', 'children': [], 'value': '1'},{'id': '62', 'type': 'None', 'children': []},{'id': '63', 'type': 'elif_clause', 'children': ['64', '79']},{'id': '64', 'type': 'boolean_operator', 'children': ['65', '73'], 'value': 'and'},{'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': 'data'},{'id': '69', 'type': 'tuple', 'children': ['70', '71', '72']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '73', 'type': 'not_operator', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '79', 'type': 'block', 'children': ['80', '92', '99', '106', '113', '140']},{'id': '80', 'type': 'if_statement', 'children': ['81', '84']},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': 'is'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '83', 'type': 'None', 'children': []},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'raise_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'concatenated_string', 'children': ['90', '91']},{'id': '90', 'type': 'string', 'children': [], 'value': "'You have to call setAdditionalCharges '"},{'id': '91', 'type': 'string', 'children': [], 'value': "'before it is possible to pass a string as price'"},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'basePrice'},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'convertPrice'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '99', 'type': 'if_statement', 'children': ['100', '103']},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': 'is'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'basePrice'},{'id': '102', 'type': 'None', 'children': []},{'id': '103', 'type': 'block', 'children': ['104']},{'id': '104', 'type': 'return_statement', 'children': ['105']},{'id': '105', 'type': 'dictionary', 'children': []},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'prices'},{'id': '109', 'type': 'dictionary', 'children': ['110']},{'id': '110', 'type': 'pair', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'basePrice'},{'id': '113', 'type': 'for_statement', 'children': ['114', '115', '116']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'role'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'additional'},{'id': '116', 'type': 'block', 'children': ['117', '126', '132']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'extraCharge'},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'convertPrice'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'additional'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'role'},{'id': '126', 'type': 'if_statement', 'children': ['127', '130']},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': 'is'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'extraCharge'},{'id': '129', 'type': 'None', 'children': []},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'continue_statement', 'children': []},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '137']},{'id': '134', 'type': 'subscript', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'prices'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'role'},{'id': '137', 'type': 'binary_operator', 'children': ['138', '139'], 'value': '+'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'basePrice'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'extraCharge'},{'id': '140', 'type': 'return_statement', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'prices'},{'id': '142', 'type': 'elif_clause', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'roles'},{'id': '144', 'type': 'block', 'children': ['145', '149', '156', '182']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'prices'},{'id': '148', 'type': 'dictionary', 'children': []},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'priceRoles'},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'roles'},{'id': '156', 'type': 'for_statement', 'children': ['157', '158', '159']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'priceData'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '159', 'type': 'block', 'children': ['160', '167', '173']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'price'},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'convertPrice'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'priceData'},{'id': '167', 'type': 'if_statement', 'children': ['168', '171']},{'id': '168', 'type': 'comparison_operator', 'children': ['169', '170'], 'value': 'is'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'price'},{'id': '170', 'type': 'None', 'children': []},{'id': '171', 'type': 'block', 'children': ['172']},{'id': '172', 'type': 'continue_statement', 'children': []},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '181']},{'id': '175', 'type': 'subscript', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'prices'},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'priceRoles'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'price'},{'id': '182', 'type': 'return_statement', 'children': ['183']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'prices'},{'id': '184', 'type': 'else_clause', 'children': ['185']},{'id': '185', 'type': 'block', 'children': ['186']},{'id': '186', 'type': 'raise_statement', 'children': ['187']},{'id': '187', 'type': 'call', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'string', 'children': [], 'value': "'This type is for prices not supported!'"}
def buildPrices(data, roles=None, regex=default_price_regex, default=None, additional={}): ''' Create a dictionary with price information. Multiple ways are supported. :rtype: :obj:`dict`: keys are role as str, values are the prices as cent count''' if isinstance(data, dict): data = [(item[0], convertPrice(item[1])) for item in data.items()] return dict([v for v in data if v[1] is not None]) elif isinstance(data, (str, float, int)) and not isinstance(data, bool): if default is None: raise ValueError('You have to call setAdditionalCharges ' 'before it is possible to pass a string as price') basePrice = convertPrice(data) if basePrice is None: return {} prices = {default: basePrice} for role in additional: extraCharge = convertPrice(additional[role]) if extraCharge is None: continue prices[role] = basePrice + extraCharge return prices elif roles: prices = {} priceRoles = iter(roles) for priceData in data: price = convertPrice(priceData) if price is None: continue prices[next(priceRoles)] = price return prices else: raise TypeError('This type is for prices not supported!')
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'toTag'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '6', 'type': 'block', 'children': ['7', '9', '18', '41', '64', '87', '110', '133', '155', '178', '207', '308']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'string', 'children': [], 'value': "''' This methods adds all data of this canteen as canteen xml tag\n to the given xml Document.\n :meth:`toXMLFeed` uses this method to create the XML Feed. So there is\n normally no need to call it directly.\n :param output: XML Document to which the data should be added\n :type output: xml.dom.DOMImplementation.createDocument\n '''"},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'canteen'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'createElement'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'string', 'children': [], 'value': "'canteen'"},{'id': '18', 'type': 'if_statement', 'children': ['19', '24']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '23'], 'value': 'is'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': '_name'},{'id': '23', 'type': 'None', 'children': []},{'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': 'canteen'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'appendChild'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': '_buildStringTag'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37', '40']},{'id': '36', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': '_name'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '41', 'type': 'if_statement', 'children': ['42', '47']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '46'], 'value': 'is'},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': '_address'},{'id': '46', 'type': 'None', 'children': []},{'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': 'canteen'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'appendChild'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '57', 'type': 'identifier', 'children': [], 'value': '_buildStringTag'},{'id': '58', 'type': 'argument_list', 'children': ['59', '60', '63']},{'id': '59', 'type': 'string', 'children': [], 'value': "'address'"},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': '_address'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '64', 'type': 'if_statement', 'children': ['65', '70']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '69'], 'value': 'is'},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': '_city'},{'id': '69', 'type': 'None', 'children': []},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'canteen'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'appendChild'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '80', 'type': 'identifier', 'children': [], 'value': '_buildStringTag'},{'id': '81', 'type': 'argument_list', 'children': ['82', '83', '86']},{'id': '82', 'type': 'string', 'children': [], 'value': "'city'"},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '85', 'type': 'identifier', 'children': [], 'value': '_city'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '87', 'type': 'if_statement', 'children': ['88', '93']},{'id': '88', 'type': 'comparison_operator', 'children': ['89', '92'], 'value': 'is'},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': '_phone'},{'id': '92', 'type': 'None', 'children': []},{'id': '93', 'type': 'block', 'children': ['94']},{'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': 'canteen'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'appendChild'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '103', 'type': 'identifier', 'children': [], 'value': '_buildStringTag'},{'id': '104', 'type': 'argument_list', 'children': ['105', '106', '109']},{'id': '105', 'type': 'string', 'children': [], 'value': "'phone'"},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '108', 'type': 'identifier', 'children': [], 'value': '_phone'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '110', 'type': 'if_statement', 'children': ['111', '116']},{'id': '111', 'type': 'comparison_operator', 'children': ['112', '115'], 'value': 'is'},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '114', 'type': 'identifier', 'children': [], 'value': '_email'},{'id': '115', 'type': 'None', 'children': []},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'canteen'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'appendChild'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '126', 'type': 'identifier', 'children': [], 'value': '_buildStringTag'},{'id': '127', 'type': 'argument_list', 'children': ['128', '129', '132']},{'id': '128', 'type': 'string', 'children': [], 'value': "'email'"},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '131', 'type': 'identifier', 'children': [], 'value': '_email'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '133', 'type': 'if_statement', 'children': ['134', '139']},{'id': '134', 'type': 'comparison_operator', 'children': ['135', '138'], 'value': 'is'},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '137', 'type': 'identifier', 'children': [], 'value': '_location'},{'id': '138', 'type': 'None', 'children': []},{'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': 'canteen'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'appendChild'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '149', 'type': 'identifier', 'children': [], 'value': '_buildLocationTag'},{'id': '150', 'type': 'argument_list', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '153', 'type': 'identifier', 'children': [], 'value': '_location'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '155', 'type': 'if_statement', 'children': ['156', '161']},{'id': '156', 'type': 'comparison_operator', 'children': ['157', '160'], 'value': 'is'},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '159', 'type': 'identifier', 'children': [], 'value': '_availability'},{'id': '160', 'type': 'None', 'children': []},{'id': '161', 'type': 'block', 'children': ['162']},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'canteen'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'appendChild'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '171', 'type': 'identifier', 'children': [], 'value': '_buildStringTag'},{'id': '172', 'type': 'argument_list', 'children': ['173', '174', '177']},{'id': '173', 'type': 'string', 'children': [], 'value': "'availability'"},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '176', 'type': 'identifier', 'children': [], 'value': '_availability'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '178', 'type': 'for_statement', 'children': ['179', '180', '194']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'feed'},{'id': '180', 'type': 'call', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '182', 'type': 'argument_list', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'feeds'},{'id': '186', 'type': 'keyword_argument', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '188', 'type': 'lambda', 'children': ['189', '191']},{'id': '189', 'type': 'lambda_parameters', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'priority'},{'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': 'canteen'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'appendChild'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'feed'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'toTag'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '207', 'type': 'for_statement', 'children': ['208', '209', '219']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '209', 'type': 'call', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'call', 'children': ['213', '218']},{'id': '213', 'type': 'attribute', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '216', 'type': 'identifier', 'children': [], 'value': '_days'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '218', 'type': 'argument_list', 'children': []},{'id': '219', 'type': 'block', 'children': ['220', '229', '240', '273', '301']},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'assignment', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '223', 'type': 'call', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'createElement'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'string', 'children': [], 'value': "'day'"},{'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': 'day'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'setAttribute'},{'id': '234', 'type': 'argument_list', 'children': ['235', '236']},{'id': '235', 'type': 'string', 'children': [], 'value': "'date'"},{'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': 'date'},{'id': '240', 'type': 'if_statement', 'children': ['241', '248']},{'id': '241', 'type': 'comparison_operator', 'children': ['242', '247'], 'value': 'is'},{'id': '242', 'type': 'subscript', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '245', 'type': 'identifier', 'children': [], 'value': '_days'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '247', 'type': 'False', 'children': []},{'id': '248', 'type': 'block', 'children': ['249', '258', '265', '272']},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'assignment', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'closed'},{'id': '252', 'type': 'call', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'createElement'},{'id': '256', 'type': 'argument_list', 'children': ['257']},{'id': '257', 'type': 'string', 'children': [], 'value': "'closed'"},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'call', 'children': ['260', '263']},{'id': '260', 'type': 'attribute', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'appendChild'},{'id': '263', 'type': 'argument_list', 'children': ['264']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'closed'},{'id': '265', 'type': 'expression_statement', 'children': ['266']},{'id': '266', 'type': 'call', 'children': ['267', '270']},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'canteen'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'appendChild'},{'id': '270', 'type': 'argument_list', 'children': ['271']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '272', 'type': 'continue_statement', 'children': []},{'id': '273', 'type': 'for_statement', 'children': ['274', '275', '280']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'categoryname'},{'id': '275', 'type': 'subscript', 'children': ['276', '279']},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '278', 'type': 'identifier', 'children': [], 'value': '_days'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '280', 'type': 'block', 'children': ['281']},{'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': 'day'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'appendChild'},{'id': '286', 'type': 'argument_list', 'children': ['287']},{'id': '287', 'type': 'call', 'children': ['288', '291']},{'id': '288', 'type': 'attribute', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '290', 'type': 'identifier', 'children': [], 'value': '_buildCategoryTag'},{'id': '291', 'type': 'argument_list', 'children': ['292', '293', '300']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'categoryname'},{'id': '293', 'type': 'subscript', 'children': ['294', '299']},{'id': '294', 'type': 'subscript', 'children': ['295', '298']},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '297', 'type': 'identifier', 'children': [], 'value': '_days'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'categoryname'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '301', 'type': 'expression_statement', 'children': ['302']},{'id': '302', 'type': 'call', 'children': ['303', '306']},{'id': '303', 'type': 'attribute', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'canteen'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'appendChild'},{'id': '306', 'type': 'argument_list', 'children': ['307']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '308', 'type': 'return_statement', 'children': ['309']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'canteen'}
def toTag(self, output): ''' This methods adds all data of this canteen as canteen xml tag to the given xml Document. :meth:`toXMLFeed` uses this method to create the XML Feed. So there is normally no need to call it directly. :param output: XML Document to which the data should be added :type output: xml.dom.DOMImplementation.createDocument ''' canteen = output.createElement('canteen') if self._name is not None: canteen.appendChild(self._buildStringTag('name', self._name, output)) if self._address is not None: canteen.appendChild(self._buildStringTag('address', self._address, output)) if self._city is not None: canteen.appendChild(self._buildStringTag('city', self._city, output)) if self._phone is not None: canteen.appendChild(self._buildStringTag('phone', self._phone, output)) if self._email is not None: canteen.appendChild(self._buildStringTag('email', self._email, output)) if self._location is not None: canteen.appendChild(self._buildLocationTag(self._location, output)) if self._availability is not None: canteen.appendChild(self._buildStringTag('availability', self._availability, output)) for feed in sorted(self.feeds, key=lambda v: v.priority): canteen.appendChild(feed.toTag(output)) for date in sorted(self._days.keys()): day = output.createElement('day') day.setAttribute('date', str(date)) if self._days[date] is False: closed = output.createElement('closed') day.appendChild(closed) canteen.appendChild(day) continue for categoryname in self._days[date]: day.appendChild(self._buildCategoryTag( categoryname, self._days[date][categoryname], output)) canteen.appendChild(day) return canteen
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '33']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'AddAnalogShortIdMsecRecord'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '12', '15', '18', '21', '24', '27', '30']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'site_service'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'time_value'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'msec'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'low_warn'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'high_warn'},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'low_alarm'},{'id': '17', 'type': 'False', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'high_alarm'},{'id': '20', 'type': 'False', 'children': []},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'oor_low'},{'id': '23', 'type': 'False', 'children': []},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'oor_high'},{'id': '26', 'type': 'False', 'children': []},{'id': '27', 'type': 'default_parameter', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'unreliable'},{'id': '29', 'type': 'False', 'children': []},{'id': '30', 'type': 'default_parameter', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'manual'},{'id': '32', 'type': 'False', 'children': []},{'id': '33', 'type': 'block', 'children': ['34', '46', '58', '68', '75', '85', '95', '105', '115', '125', '135', '145', '155', '162', '183']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'szService'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'c_char_p'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'site_service'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'szPointId'},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'c_char_p'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'tTime'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'c_long'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'time_value'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'dValue'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'c_double'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'bLowWarning'},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'c_int'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'low_warn'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'bHighWarning'},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'c_int'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'high_warn'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'bLowAlarm'},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'c_int'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'low_alarm'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'bHighAlarm'},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'c_int'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'high_alarm'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'bOutOfRangeLow'},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'c_int'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'oor_low'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'bOutOfRangeHigh'},{'id': '128', 'type': 'call', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'c_int'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'oor_high'},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'bUnReliable'},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'c_int'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'unreliable'},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'bManual'},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'c_int'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'manual'},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'usMsec'},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'c_ushort'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'msec'},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'nRet'},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'dnaserv_dll'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'DnaAddAnalogShortIdMsecRecord'},{'id': '169', 'type': 'argument_list', 'children': ['170', '171', '172', '173', '174', '175', '176', '177', '178', '179', '180', '181', '182']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'szService'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'szPointId'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'tTime'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'dValue'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'bLowWarning'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'bHighWarning'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'bLowAlarm'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'bHighAlarm'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'bOutOfRangeLow'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'bOutOfRangeHigh'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'bUnReliable'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'bManual'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'usMsec'},{'id': '183', 'type': 'return_statement', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'nRet'}
def AddAnalogShortIdMsecRecord(site_service, tag, time_value, msec, value, low_warn=False, high_warn=False, low_alarm=False, high_alarm=False, oor_low=False, oor_high=False, unreliable=False, manual=False): szService = c_char_p(site_service.encode('utf-8')) szPointId = c_char_p(tag.encode('utf-8')) tTime = c_long(int(time_value)) dValue = c_double(value) bLowWarning = c_int(int(low_warn)) bHighWarning = c_int(int(high_warn)) bLowAlarm = c_int(int(low_alarm)) bHighAlarm = c_int(int(high_alarm)) bOutOfRangeLow = c_int(int(oor_low)) bOutOfRangeHigh = c_int(int(oor_high)) bUnReliable = c_int(int(unreliable)) bManual = c_int(int(manual)) usMsec = c_ushort(msec) nRet = dnaserv_dll.DnaAddAnalogShortIdMsecRecord(szService, szPointId, tTime, dValue, bLowWarning, bHighWarning, bLowAlarm, bHighAlarm, bOutOfRangeLow, bOutOfRangeHigh, bUnReliable, bManual, usMsec) return nRet
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'update_node_ids'},{'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': 'sub_job_num'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '27', '31', '35', '67', '82', '87', '104', '121', '133']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'dag_id'},{'id': '12', 'type': 'conditional_expression', 'children': ['13', '20', '21'], 'value': 'if'},{'id': '13', 'type': 'binary_operator', 'children': ['14', '15'], 'value': '%'},{'id': '14', 'type': 'string', 'children': [], 'value': "'%s.%s'"},{'id': '15', 'type': 'tuple', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'cluster_id'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'sub_job_num'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'sub_job_num'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'cluster_id'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'job_delimiter'},{'id': '30', 'type': 'string', 'children': [], 'value': "'+++'"},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'attr_delimiter'},{'id': '34', 'type': 'string', 'children': [], 'value': "';;;'"},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '38', 'type': 'list', 'children': ['39', '40', '45', '46', '47', '52', '53', '54', '59', '60', '61', '66'], 'value': '[\n \'-format\', \'"%d\' + attr_delimiter + \'"\', \'ClusterId\',\n \'-format\', \'"%v\' + attr_delimiter + \'"\', \'Cmd\',\n \'-format\', \'"%v\' + attr_delimiter + \'"\', \'Args\',\n \'-format\', \'"%v\' + job_delimiter + \'"\', \'Arguments\'\n ]'},{'id': '39', 'type': 'string', 'children': [], 'value': "'-format'"},{'id': '40', 'type': 'binary_operator', 'children': ['41', '44'], 'value': '+'},{'id': '41', 'type': 'binary_operator', 'children': ['42', '43'], 'value': '+'},{'id': '42', 'type': 'string', 'children': [], 'value': '\'"%d\''},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'attr_delimiter'},{'id': '44', 'type': 'string', 'children': [], 'value': '\'"\''},{'id': '45', 'type': 'string', 'children': [], 'value': "'ClusterId'"},{'id': '46', 'type': 'string', 'children': [], 'value': "'-format'"},{'id': '47', 'type': 'binary_operator', 'children': ['48', '51'], 'value': '+'},{'id': '48', 'type': 'binary_operator', 'children': ['49', '50'], 'value': '+'},{'id': '49', 'type': 'string', 'children': [], 'value': '\'"%v\''},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'attr_delimiter'},{'id': '51', 'type': 'string', 'children': [], 'value': '\'"\''},{'id': '52', 'type': 'string', 'children': [], 'value': "'Cmd'"},{'id': '53', 'type': 'string', 'children': [], 'value': "'-format'"},{'id': '54', 'type': 'binary_operator', 'children': ['55', '58'], 'value': '+'},{'id': '55', 'type': 'binary_operator', 'children': ['56', '57'], 'value': '+'},{'id': '56', 'type': 'string', 'children': [], 'value': '\'"%v\''},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'attr_delimiter'},{'id': '58', 'type': 'string', 'children': [], 'value': '\'"\''},{'id': '59', 'type': 'string', 'children': [], 'value': "'Args'"},{'id': '60', 'type': 'string', 'children': [], 'value': "'-format'"},{'id': '61', 'type': 'binary_operator', 'children': ['62', '65'], 'value': '+'},{'id': '62', 'type': 'binary_operator', 'children': ['63', '64'], 'value': '+'},{'id': '63', 'type': 'string', 'children': [], 'value': '\'"%v\''},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'job_delimiter'},{'id': '65', 'type': 'string', 'children': [], 'value': '\'"\''},{'id': '66', 'type': 'string', 'children': [], 'value': "'Arguments'"},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'string', 'children': [], 'value': "'condor_q -constraint DAGManJobID=={0} {1} && condor_history -constraint DAGManJobID=={0} {1}'"},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'dag_id'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'string', 'children': [], 'value': "' '"},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': '_args'},{'id': '85', 'type': 'list', 'children': ['86'], 'value': '[cmd]'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '92']},{'id': '89', 'type': 'pattern_list', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '95', 'type': 'identifier', 'children': [], 'value': '_execute'},{'id': '96', 'type': 'argument_list', 'children': ['97', '98', '101']},{'id': '97', 'type': 'identifier', 'children': [], 'value': '_args'},{'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'shell'},{'id': '100', 'type': 'True', 'children': []},{'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'run_in_job_dir'},{'id': '103', 'type': 'False', 'children': []},{'id': '104', 'type': 'if_statement', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '106', 'type': 'block', 'children': ['107', '116']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '112', 'type': 'argument_list', 'children': ['113', '114', '115']},{'id': '113', 'type': 'string', 'children': [], 'value': "'Error while associating ids for jobs dag %s: %s'"},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'dag_id'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '116', 'type': 'raise_statement', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'HTCondorError'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '121', 'type': 'if_statement', 'children': ['122', '124']},{'id': '122', 'type': 'not_operator', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '130', 'type': 'argument_list', 'children': ['131', '132']},{'id': '131', 'type': 'string', 'children': [], 'value': "'Error while associating ids for jobs in dag %s: No jobs found for dag.'"},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'dag_id'},{'id': '133', 'type': 'try_statement', 'children': ['134', '282']},{'id': '134', 'type': 'block', 'children': ['135', '144']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'jobs_out'},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'job_delimiter'},{'id': '144', 'type': 'for_statement', 'children': ['145', '146', '149']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '148', 'type': 'identifier', 'children': [], 'value': '_node_set'},{'id': '149', 'type': 'block', 'children': ['150', '156', '166']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '156', 'type': 'if_statement', 'children': ['157', '164']},{'id': '157', 'type': 'comparison_operator', 'children': ['158', '161'], 'value': '!='},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'cluster_id'},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'NULL_CLUSTER_ID'},{'id': '164', 'type': 'block', 'children': ['165']},{'id': '165', 'type': 'continue_statement', 'children': []},{'id': '166', 'type': 'for_statement', 'children': ['167', '168', '169']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'job_out'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'jobs_out'},{'id': '169', 'type': 'block', 'children': ['170', '179', '192', '232', '238', '253']},{'id': '170', 'type': 'if_statement', 'children': ['171', '177']},{'id': '171', 'type': 'boolean_operator', 'children': ['172', '174'], 'value': 'or'},{'id': '172', 'type': 'not_operator', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'job_out'},{'id': '174', 'type': 'comparison_operator', 'children': ['175', '176'], 'value': 'not'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'attr_delimiter'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'job_out'},{'id': '177', 'type': 'block', 'children': ['178']},{'id': '178', 'type': 'continue_statement', 'children': []},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '186']},{'id': '181', 'type': 'pattern_list', 'children': ['182', '183', '184', '185']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'cluster_id'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '184', 'type': 'identifier', 'children': [], 'value': '_args'},{'id': '185', 'type': 'identifier', 'children': [], 'value': '_arguments'},{'id': '186', 'type': 'call', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'job_out'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'attr_delimiter'},{'id': '192', 'type': 'if_statement', 'children': ['193', '200', '209', '222']},{'id': '193', 'type': 'boolean_operator', 'children': ['194', '197'], 'value': 'and'},{'id': '194', 'type': 'comparison_operator', 'children': ['195', '196'], 'value': '=='},{'id': '195', 'type': 'identifier', 'children': [], 'value': '_args'},{'id': '196', 'type': 'string', 'children': [], 'value': "'undefined'"},{'id': '197', 'type': 'comparison_operator', 'children': ['198', '199'], 'value': '!='},{'id': '198', 'type': 'identifier', 'children': [], 'value': '_arguments'},{'id': '199', 'type': 'string', 'children': [], 'value': "'undefined'"},{'id': '200', 'type': 'block', 'children': ['201']},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '204', 'type': 'call', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': '_arguments'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '208', 'type': 'argument_list', 'children': []},{'id': '209', 'type': 'elif_clause', 'children': ['210', '217']},{'id': '210', 'type': 'boolean_operator', 'children': ['211', '214'], 'value': 'and'},{'id': '211', 'type': 'comparison_operator', 'children': ['212', '213'], 'value': '=='},{'id': '212', 'type': 'identifier', 'children': [], 'value': '_args'},{'id': '213', 'type': 'string', 'children': [], 'value': "'undefined'"},{'id': '214', 'type': 'comparison_operator', 'children': ['215', '216'], 'value': '=='},{'id': '215', 'type': 'identifier', 'children': [], 'value': '_arguments'},{'id': '216', 'type': 'string', 'children': [], 'value': "'undefined'"},{'id': '217', 'type': 'block', 'children': ['218']},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'assignment', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '221', 'type': 'None', 'children': []},{'id': '222', 'type': 'else_clause', 'children': ['223']},{'id': '223', 'type': 'block', 'children': ['224']},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '227', 'type': 'call', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': '_args'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '231', 'type': 'argument_list', 'children': []},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'job_cmd'},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'executable'},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'job_args'},{'id': '241', 'type': 'conditional_expression', 'children': ['242', '249', '252'], 'value': 'if'},{'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': 'job'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'arguments'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '248', 'type': 'argument_list', 'children': []},{'id': '249', 'type': 'attribute', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'arguments'},{'id': '252', 'type': 'None', 'children': []},{'id': '253', 'type': 'if_statement', 'children': ['254', '261']},{'id': '254', 'type': 'boolean_operator', 'children': ['255', '258'], 'value': 'and'},{'id': '255', 'type': 'comparison_operator', 'children': ['256', '257'], 'value': 'in'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'job_cmd'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '258', 'type': 'comparison_operator', 'children': ['259', '260'], 'value': '=='},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'job_args'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '261', 'type': 'block', 'children': ['262', '272', '281']},{'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': 'log'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '267', 'type': 'argument_list', 'children': ['268', '269', '270', '271']},{'id': '268', 'type': 'string', 'children': [], 'value': "'Linking cluster_id %s to job with command and arguments: %s %s'"},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'cluster_id'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'job_cmd'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'job_args'},{'id': '272', 'type': 'expression_statement', 'children': ['273']},{'id': '273', 'type': 'assignment', 'children': ['274', '277']},{'id': '274', 'type': 'attribute', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '276', 'type': 'identifier', 'children': [], 'value': '_cluster_id'},{'id': '277', 'type': 'call', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '279', 'type': 'argument_list', 'children': ['280']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'cluster_id'},{'id': '281', 'type': 'break_statement', 'children': []},{'id': '282', 'type': 'except_clause', 'children': ['283', '287']},{'id': '283', 'type': 'as_pattern', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '285', 'type': 'as_pattern_target', 'children': ['286']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '287', 'type': 'block', 'children': ['288']},{'id': '288', 'type': 'expression_statement', 'children': ['289']},{'id': '289', 'type': 'call', 'children': ['290', '293']},{'id': '290', 'type': 'attribute', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '293', 'type': 'argument_list', 'children': ['294']},{'id': '294', 'type': 'call', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '296', 'type': 'argument_list', 'children': ['297']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'e'}
def update_node_ids(self, sub_job_num=None): dag_id = '%s.%s' % (self.cluster_id, sub_job_num) if sub_job_num else str(self.cluster_id) job_delimiter = '+++' attr_delimiter = ';;;' format = [ '-format', '"%d' + attr_delimiter + '"', 'ClusterId', '-format', '"%v' + attr_delimiter + '"', 'Cmd', '-format', '"%v' + attr_delimiter + '"', 'Args', '-format', '"%v' + job_delimiter + '"', 'Arguments' ] cmd = 'condor_q -constraint DAGManJobID=={0} {1} && condor_history -constraint DAGManJobID=={0} {1}'.format(dag_id, ' '.join(format)) _args = [cmd] out, err = self._execute(_args, shell=True, run_in_job_dir=False) if err: log.error('Error while associating ids for jobs dag %s: %s', dag_id, err) raise HTCondorError(err) if not out: log.warning('Error while associating ids for jobs in dag %s: No jobs found for dag.', dag_id) try: jobs_out = out.split(job_delimiter) for node in self._node_set: job = node.job if job.cluster_id != job.NULL_CLUSTER_ID: continue for job_out in jobs_out: if not job_out or attr_delimiter not in job_out: continue cluster_id, cmd, _args, _arguments = job_out.split(attr_delimiter) if _args == 'undefined' and _arguments != 'undefined': args = _arguments.strip() elif _args == 'undefined' and _arguments == 'undefined': args = None else: args = _args.strip() job_cmd = job.executable job_args = job.arguments.strip() if job.arguments else None if job_cmd in cmd and job_args == args: log.info('Linking cluster_id %s to job with command and arguments: %s %s', cluster_id, job_cmd, job_args) job._cluster_id = int(cluster_id) break except ValueError as e: log.warning(str(e))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'concat_cols'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'df1'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'df2'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'idx_col'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'df1_cols'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'df2_cols'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'df1_suffix'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'df2_suffix'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'wc_cols'},{'id': '13', 'type': 'list', 'children': [], 'value': '[]'},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'suffix_all'},{'id': '16', 'type': 'False', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '27', '36', '81', '107', '182', '190', '198']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'df1'},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'df1'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'set_index'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'idx_col'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'df2'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'df2'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'set_index'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'idx_col'},{'id': '36', 'type': 'if_statement', 'children': ['37', '44']},{'id': '37', 'type': 'not_operator', 'children': ['38']},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '43'], 'value': '=='},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'wc_cols'},{'id': '43', 'type': 'integer', 'children': [], 'value': '0'},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'for_statement', 'children': ['46', '47', '48']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'wc'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'wc_cols'},{'id': '48', 'type': 'block', 'children': ['49', '65']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'df1_cols'},{'id': '52', 'type': 'binary_operator', 'children': ['53', '54'], 'value': '+'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'df1_cols'},{'id': '54', 'type': 'list_comprehension', 'children': ['55', '56', '61']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '56', 'type': 'for_in_clause', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'df1'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '61', 'type': 'if_clause', 'children': ['62']},{'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'in'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'wc'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'df2_cols'},{'id': '68', 'type': 'binary_operator', 'children': ['69', '70'], 'value': '+'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'df2_cols'},{'id': '70', 'type': 'list_comprehension', 'children': ['71', '72', '77']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '72', 'type': 'for_in_clause', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'df2'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '77', 'type': 'if_clause', 'children': ['78']},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': 'in'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'wc'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'combo'},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'concat'},{'id': '88', 'type': 'argument_list', 'children': ['89', '104']},{'id': '89', 'type': 'list', 'children': ['90', '97'], 'value': '[df1.loc[:,df1_cols],df2.loc[:,df2_cols]]'},{'id': '90', 'type': 'subscript', 'children': ['91', '94', '96']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'df1'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '94', 'type': 'slice', 'children': ['95']},{'id': '95', 'type': 'colon', 'children': []},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'df1_cols'},{'id': '97', 'type': 'subscript', 'children': ['98', '101', '103']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'df2'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '101', 'type': 'slice', 'children': ['102']},{'id': '102', 'type': 'colon', 'children': []},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'df2_cols'},{'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '106', 'type': 'integer', 'children': [], 'value': '1'},{'id': '107', 'type': 'if_statement', 'children': ['108', '109', '134']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'suffix_all'},{'id': '109', 'type': 'block', 'children': ['110', '122']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'df1_cols'},{'id': '113', 'type': 'list_comprehension', 'children': ['114', '119']},{'id': '114', 'type': 'binary_operator', 'children': ['115', '116'], 'value': '%'},{'id': '115', 'type': 'string', 'children': [], 'value': '"%s%s"'},{'id': '116', 'type': 'tuple', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'df1_suffix'},{'id': '119', 'type': 'for_in_clause', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'df1_cols'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'df2_cols'},{'id': '125', 'type': 'list_comprehension', 'children': ['126', '131']},{'id': '126', 'type': 'binary_operator', 'children': ['127', '128'], 'value': '%'},{'id': '127', 'type': 'string', 'children': [], 'value': '"%s%s"'},{'id': '128', 'type': 'tuple', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'df2_suffix'},{'id': '131', 'type': 'for_in_clause', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'df2_cols'},{'id': '134', 'type': 'else_clause', 'children': ['135']},{'id': '135', 'type': 'block', 'children': ['136', '148']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'common_cols'},{'id': '139', 'type': 'list_comprehension', 'children': ['140', '141', '144']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '141', 'type': 'for_in_clause', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'df1_cols'},{'id': '144', 'type': 'if_clause', 'children': ['145']},{'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': 'in'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'df2_cols'},{'id': '148', 'type': 'for_statement', 'children': ['149', '150', '151']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'common_cols'},{'id': '151', 'type': 'block', 'children': ['152', '167']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '162']},{'id': '154', 'type': 'subscript', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'df1_cols'},{'id': '156', 'type': 'call', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'df1_cols'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '162', 'type': 'binary_operator', 'children': ['163', '164'], 'value': '%'},{'id': '163', 'type': 'string', 'children': [], 'value': '"%s%s"'},{'id': '164', 'type': 'tuple', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'df1_suffix'},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '177']},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'df2_cols'},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'df2_cols'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '177', 'type': 'binary_operator', 'children': ['178', '179'], 'value': '%'},{'id': '178', 'type': 'string', 'children': [], 'value': '"%s%s"'},{'id': '179', 'type': 'tuple', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'df2_suffix'},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'combo'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '187', 'type': 'binary_operator', 'children': ['188', '189'], 'value': '+'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'df1_cols'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'df2_cols'},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '197']},{'id': '192', 'type': 'attribute', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'combo'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'idx_col'},{'id': '198', 'type': 'return_statement', 'children': ['199']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'combo'}
def concat_cols(df1,df2,idx_col,df1_cols,df2_cols, df1_suffix,df2_suffix,wc_cols=[],suffix_all=False): df1=df1.set_index(idx_col) df2=df2.set_index(idx_col) if not len(wc_cols)==0: for wc in wc_cols: df1_cols=df1_cols+[c for c in df1.columns if wc in c] df2_cols=df2_cols+[c for c in df2.columns if wc in c] combo=pd.concat([df1.loc[:,df1_cols],df2.loc[:,df2_cols]],axis=1) if suffix_all: df1_cols=["%s%s" % (c,df1_suffix) for c in df1_cols] df2_cols=["%s%s" % (c,df2_suffix) for c in df2_cols] else: common_cols=[col for col in df1_cols if col in df2_cols] for col in common_cols: df1_cols[df1_cols.index(col)]="%s%s" % (col,df1_suffix) df2_cols[df2_cols.index(col)]="%s%s" % (col,df2_suffix) combo.columns=df1_cols+df2_cols combo.index.name=idx_col return combo
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_json'},{'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': 'indent'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '10', 'type': 'True', 'children': []},{'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': 'json'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '17', 'type': 'argument_list', 'children': ['18', '23', '26']},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'to_dict'},{'id': '22', 'type': 'argument_list', 'children': []},{'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'sort_keys'}
def to_json(self, indent=None, sort_keys=True): return json.dumps(self.to_dict(), indent=indent, sort_keys=sort_keys)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_validate_method_decoration'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'meta'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'class_'},{'id': '6', 'type': 'block', 'children': ['7', '17', '40']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'super_mro'},{'id': '10', 'type': 'subscript', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'class_'},{'id': '13', 'type': 'identifier', 'children': [], 'value': '__mro__'},{'id': '14', 'type': 'slice', 'children': ['15', '16']},{'id': '15', 'type': 'integer', 'children': [], 'value': '1'},{'id': '16', 'type': 'colon', 'children': []},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'own_methods'},{'id': '20', 'type': 'generator_expression', 'children': ['21', '24', '35']},{'id': '21', 'type': 'tuple', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '24', 'type': 'for_in_clause', 'children': ['25', '28']},{'id': '25', 'type': 'pattern_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '28', 'type': 'call', 'children': ['29', '34']},{'id': '29', 'type': 'attribute', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'class_'},{'id': '32', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '34', 'type': 'argument_list', 'children': []},{'id': '35', 'type': 'if_clause', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'is_method'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '40', 'type': 'for_statement', 'children': ['41', '44', '45']},{'id': '41', 'type': 'pattern_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'own_methods'},{'id': '45', 'type': 'block', 'children': ['46', '74']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '51']},{'id': '48', 'type': 'pattern_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'shadowed_method'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'base_class'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '53', 'type': 'argument_list', 'children': ['54', '71']},{'id': '54', 'type': 'generator_expression', 'children': ['55', '62', '65']},{'id': '55', 'type': 'tuple', 'children': ['56', '61']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '58', 'type': 'argument_list', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '62', 'type': 'for_in_clause', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'super_mro'},{'id': '65', 'type': 'if_clause', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '68', 'type': 'argument_list', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '71', 'type': 'tuple', 'children': ['72', '73']},{'id': '72', 'type': 'None', 'children': []},{'id': '73', 'type': 'None', 'children': []},{'id': '74', 'type': 'if_statement', 'children': ['75', '81', '176']},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'meta'},{'id': '78', 'type': 'identifier', 'children': [], 'value': '_is_override'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '81', 'type': 'block', 'children': ['82', '100', '122', '131', '167']},{'id': '82', 'type': 'if_statement', 'children': ['83', '85']},{'id': '83', 'type': 'not_operator', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'shadowed_method'},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'raise_statement', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'ClassError'},{'id': '89', 'type': 'argument_list', 'children': ['90', '97']},{'id': '90', 'type': 'binary_operator', 'children': ['91', '92'], 'value': '%'},{'id': '91', 'type': 'string', 'children': [], 'value': '"unnecessary @override on %s.%s"'},{'id': '92', 'type': 'tuple', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'class_'},{'id': '95', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'class_'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'class_'},{'id': '100', 'type': 'if_statement', 'children': ['101', '107']},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'meta'},{'id': '104', 'type': 'identifier', 'children': [], 'value': '_is_final'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'shadowed_method'},{'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': 'ClassError'},{'id': '111', 'type': 'argument_list', 'children': ['112', '119']},{'id': '112', 'type': 'binary_operator', 'children': ['113', '114'], 'value': '%'},{'id': '113', 'type': 'string', 'children': [], 'value': '"illegal @override on a @final method %s.%s"'},{'id': '114', 'type': 'tuple', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'base_class'},{'id': '117', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'class_'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'class_'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'override_base'},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'meta'},{'id': '128', 'type': 'identifier', 'children': [], 'value': '_get_override_base'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '131', 'type': 'if_statement', 'children': ['132', '137']},{'id': '132', 'type': 'boolean_operator', 'children': ['133', '134'], 'value': 'and'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'override_base'},{'id': '134', 'type': 'comparison_operator', 'children': ['135', '136'], 'value': 'is'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'base_class'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'override_base'},{'id': '137', 'type': 'block', 'children': ['138']},{'id': '138', 'type': 'if_statement', 'children': ['139', '143', '157']},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'is_class'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'override_base'},{'id': '143', 'type': 'block', 'children': ['144']},{'id': '144', 'type': 'raise_statement', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'ClassError'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'binary_operator', 'children': ['149', '150'], 'value': '%'},{'id': '149', 'type': 'string', 'children': [], 'value': '"incorrect override base: expected %s, got %s"'},{'id': '150', 'type': 'tuple', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'base_class'},{'id': '153', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'override_base'},{'id': '156', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '157', 'type': 'else_clause', 'children': ['158']},{'id': '158', 'type': 'block', 'children': ['159']},{'id': '159', 'type': 'raise_statement', 'children': ['160']},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'ClassError'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'binary_operator', 'children': ['164', '165'], 'value': '%'},{'id': '164', 'type': 'string', 'children': [], 'value': '"invalid override base specified: %s"'},{'id': '165', 'type': 'tuple', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'override_base'},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'setattr'},{'id': '170', 'type': 'argument_list', 'children': ['171', '172', '173']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'class_'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '176', 'type': 'else_clause', 'children': ['177']},{'id': '177', 'type': 'block', 'children': ['178']},{'id': '178', 'type': 'if_statement', 'children': ['179', '186']},{'id': '179', 'type': 'boolean_operator', 'children': ['180', '181'], 'value': 'and'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'shadowed_method'},{'id': '181', 'type': 'comparison_operator', 'children': ['182', '183'], 'value': 'not'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'meta'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'OVERRIDE_EXEMPTIONS'},{'id': '186', 'type': 'block', 'children': ['187', '224']},{'id': '187', 'type': 'if_statement', 'children': ['188', '194', '209']},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'meta'},{'id': '191', 'type': 'identifier', 'children': [], 'value': '_is_final'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'shadowed_method'},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '198', 'type': 'binary_operator', 'children': ['199', '200'], 'value': '%'},{'id': '199', 'type': 'string', 'children': [], 'value': '"%s.%s is hiding a @final method %s.%s"'},{'id': '200', 'type': 'tuple', 'children': ['201', '204', '205', '208']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'class_'},{'id': '203', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'base_class'},{'id': '207', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '209', 'type': 'else_clause', 'children': ['210']},{'id': '210', 'type': 'block', 'children': ['211']},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '214', 'type': '()', 'children': ['215']},{'id': '215', 'type': 'binary_operator', 'children': ['216', '219'], 'value': '%'},{'id': '216', 'type': 'concatenated_string', 'children': ['217', '218']},{'id': '217', 'type': 'string', 'children': [], 'value': '"overridden method %s.%s "'},{'id': '218', 'type': 'string', 'children': [], 'value': '"must be marked with @override"'},{'id': '219', 'type': 'tuple', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'class_'},{'id': '222', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '224', 'type': 'raise_statement', 'children': ['225']},{'id': '225', 'type': 'call', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'ClassError'},{'id': '227', 'type': 'argument_list', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '229', 'type': 'keyword_argument', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'class_'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'class_'}
def _validate_method_decoration(meta, class_): super_mro = class_.__mro__[1:] own_methods = ((name, member) for name, member in class_.__dict__.items() if is_method(member)) for name, method in own_methods: shadowed_method, base_class = next( ((getattr(base, name), base) for base in super_mro if hasattr(base, name)), (None, None) ) if meta._is_override(method): if not shadowed_method: raise ClassError("unnecessary @override on %s.%s" % ( class_.__name__, name), class_=class_) if meta._is_final(shadowed_method): raise ClassError( "illegal @override on a @final method %s.%s" % ( base_class.__name__, name), class_=class_) override_base = meta._get_override_base(method) if override_base and base_class is not override_base: if is_class(override_base): raise ClassError( "incorrect override base: expected %s, got %s" % ( base_class.__name__, override_base.__name__)) else: raise ClassError( "invalid override base specified: %s" % ( override_base,)) setattr(class_, name, method.method) else: if shadowed_method and name not in meta.OVERRIDE_EXEMPTIONS: if meta._is_final(shadowed_method): msg = "%s.%s is hiding a @final method %s.%s" % ( class_.__name__, name, base_class.__name__, name) else: msg = ("overridden method %s.%s " "must be marked with @override" % ( class_.__name__, name)) raise ClassError(msg, class_=class_)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_parse_status'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'bug_el'},{'id': '5', 'type': 'block', 'children': ['6', '12', '40', '57', '74', '97', '109', '121', '133', '145', '168', '191', '214', '239', '264', '285', '302']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'bug'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'Bugreport'},{'id': '11', 'type': 'argument_list', 'children': []},{'id': '12', 'type': 'for_statement', 'children': ['13', '14', '26']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '14', 'type': 'tuple', 'children': ['15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25']},{'id': '15', 'type': 'string', 'children': [], 'value': "'originator'"},{'id': '16', 'type': 'string', 'children': [], 'value': "'subject'"},{'id': '17', 'type': 'string', 'children': [], 'value': "'msgid'"},{'id': '18', 'type': 'string', 'children': [], 'value': "'package'"},{'id': '19', 'type': 'string', 'children': [], 'value': "'severity'"},{'id': '20', 'type': 'string', 'children': [], 'value': "'owner'"},{'id': '21', 'type': 'string', 'children': [], 'value': "'summary'"},{'id': '22', 'type': 'string', 'children': [], 'value': "'location'"},{'id': '23', 'type': 'string', 'children': [], 'value': "'source'"},{'id': '24', 'type': 'string', 'children': [], 'value': "'pending'"},{'id': '25', 'type': 'string', 'children': [], 'value': "'forwarded'"},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'setattr'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32', '33']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'bug'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': '_parse_string_el'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'bug_el'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'field'},{'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': 'bug'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'utcfromtimestamp'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'bug_el'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'string', 'children': [], 'value': "'date'"},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'bug'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'log_modified'},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'utcfromtimestamp'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'bug_el'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'string', 'children': [], 'value': "'log_modified'"},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'bug'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '79', 'type': 'list_comprehension', 'children': ['80', '84']},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': '_uc'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '84', 'type': 'for_in_clause', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '86', 'type': 'call', 'children': ['87', '96']},{'id': '87', 'type': 'attribute', 'children': ['88', '95']},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'bug_el'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'string', 'children': [], 'value': "'tags'"},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '96', 'type': 'argument_list', 'children': []},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'bug'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'done'},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': '_parse_bool'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'bug_el'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'string', 'children': [], 'value': "'done'"},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'bug'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'archived'},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': '_parse_bool'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'bug_el'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'string', 'children': [], 'value': "'archived'"},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'bug'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'unarchived'},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': '_parse_bool'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'bug_el'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'string', 'children': [], 'value': "'unarchived'"},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'bug'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'bug_num'},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'bug_el'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'string', 'children': [], 'value': "'bug_num'"},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'bug'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'mergedwith'},{'id': '150', 'type': 'list_comprehension', 'children': ['151', '155']},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '155', 'type': 'for_in_clause', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '157', 'type': 'call', 'children': ['158', '167']},{'id': '158', 'type': 'attribute', 'children': ['159', '166']},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'bug_el'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'string', 'children': [], 'value': "'mergedwith'"},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '167', 'type': 'argument_list', 'children': []},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'bug'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'blockedby'},{'id': '173', 'type': 'list_comprehension', 'children': ['174', '178']},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '178', 'type': 'for_in_clause', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '180', 'type': 'call', 'children': ['181', '190']},{'id': '181', 'type': 'attribute', 'children': ['182', '189']},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'bug_el'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'string', 'children': [], 'value': "'blockedby'"},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '190', 'type': 'argument_list', 'children': []},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'bug'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'blocks'},{'id': '196', 'type': 'list_comprehension', 'children': ['197', '201']},{'id': '197', 'type': 'call', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '201', 'type': 'for_in_clause', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '203', 'type': 'call', 'children': ['204', '213']},{'id': '204', 'type': 'attribute', 'children': ['205', '212']},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'call', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'bug_el'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'string', 'children': [], 'value': "'blocks'"},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '213', 'type': 'argument_list', 'children': []},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'assignment', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'bug'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'found_versions'},{'id': '219', 'type': 'list_comprehension', 'children': ['220', '227']},{'id': '220', 'type': 'call', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': '_uc'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '227', 'type': 'for_in_clause', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '229', 'type': 'boolean_operator', 'children': ['230', '238'], 'value': 'or'},{'id': '230', 'type': 'call', 'children': ['231', '237']},{'id': '231', 'type': 'attribute', 'children': ['232', '236']},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'bug_el'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'string', 'children': [], 'value': "'found_versions'"},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '237', 'type': 'argument_list', 'children': []},{'id': '238', 'type': 'list', 'children': [], 'value': '[]'},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'assignment', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'bug'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'fixed_versions'},{'id': '244', 'type': 'list_comprehension', 'children': ['245', '252']},{'id': '245', 'type': 'call', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': '_uc'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'call', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '252', 'type': 'for_in_clause', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '254', 'type': 'boolean_operator', 'children': ['255', '263'], 'value': 'or'},{'id': '255', 'type': 'call', 'children': ['256', '262']},{'id': '256', 'type': 'attribute', 'children': ['257', '261']},{'id': '257', 'type': 'call', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'bug_el'},{'id': '259', 'type': 'argument_list', 'children': ['260']},{'id': '260', 'type': 'string', 'children': [], 'value': "'fixed_versions'"},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '262', 'type': 'argument_list', 'children': []},{'id': '263', 'type': 'list', 'children': [], 'value': '[]'},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'assignment', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'affects'},{'id': '267', 'type': 'list_comprehension', 'children': ['268', '269', '283']},{'id': '268', 'type': 'identifier', 'children': [], 'value': '_f'},{'id': '269', 'type': 'for_in_clause', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': '_f'},{'id': '271', 'type': 'call', 'children': ['272', '281']},{'id': '272', 'type': 'attribute', 'children': ['273', '280']},{'id': '273', 'type': 'call', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '275', 'type': 'argument_list', 'children': ['276']},{'id': '276', 'type': 'call', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'bug_el'},{'id': '278', 'type': 'argument_list', 'children': ['279']},{'id': '279', 'type': 'string', 'children': [], 'value': "'affects'"},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '281', 'type': 'argument_list', 'children': ['282']},{'id': '282', 'type': 'string', 'children': [], 'value': "','"},{'id': '283', 'type': 'if_clause', 'children': ['284']},{'id': '284', 'type': 'identifier', 'children': [], 'value': '_f'},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '290']},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'bug'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'affects'},{'id': '290', 'type': 'list_comprehension', 'children': ['291', '299']},{'id': '291', 'type': 'call', 'children': ['292', '298']},{'id': '292', 'type': 'attribute', 'children': ['293', '297']},{'id': '293', 'type': 'call', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': '_uc'},{'id': '295', 'type': 'argument_list', 'children': ['296']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '298', 'type': 'argument_list', 'children': []},{'id': '299', 'type': 'for_in_clause', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'affects'},{'id': '302', 'type': 'return_statement', 'children': ['303']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'bug'}
def _parse_status(bug_el): bug = Bugreport() for field in ('originator', 'subject', 'msgid', 'package', 'severity', 'owner', 'summary', 'location', 'source', 'pending', 'forwarded'): setattr(bug, field, _parse_string_el(bug_el(field))) bug.date = datetime.utcfromtimestamp(float(bug_el('date'))) bug.log_modified = datetime.utcfromtimestamp(float(bug_el('log_modified'))) bug.tags = [_uc(tag) for tag in str(bug_el('tags')).split()] bug.done = _parse_bool(bug_el('done')) bug.archived = _parse_bool(bug_el('archived')) bug.unarchived = _parse_bool(bug_el('unarchived')) bug.bug_num = int(bug_el('bug_num')) bug.mergedwith = [int(i) for i in str(bug_el('mergedwith')).split()] bug.blockedby = [int(i) for i in str(bug_el('blockedby')).split()] bug.blocks = [int(i) for i in str(bug_el('blocks')).split()] bug.found_versions = [_uc(str(el)) for el in bug_el('found_versions').children() or []] bug.fixed_versions = [_uc(str(el)) for el in bug_el('fixed_versions').children() or []] affects = [_f for _f in str(bug_el('affects')).split(',') if _f] bug.affects = [_uc(a).strip() for a in affects] return bug
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'set'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '7', 'type': 'block', 'children': ['8', '62', '73', '100', '123', '141', '166', '237']},{'id': '8', 'type': 'function_definition', 'children': ['9', '10', '15']},{'id': '9', 'type': 'function_name', 'children': [], 'value': 'escape_new_syntax'},{'id': '10', 'type': 'parameters', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'double_quote_escape'},{'id': '14', 'type': 'string', 'children': [], 'value': '\'"\''},{'id': '15', 'type': 'block', 'children': ['16', '23', '33', '45', '60']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32']},{'id': '31', 'type': 'string', 'children': [], 'value': '"\'"'},{'id': '32', 'type': 'string', 'children': [], 'value': '"\'\'"'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42']},{'id': '41', 'type': 'string', 'children': [], 'value': '\'"\''},{'id': '42', 'type': 'binary_operator', 'children': ['43', '44'], 'value': '%'},{'id': '43', 'type': 'string', 'children': [], 'value': '\'%s"\''},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'double_quote_escape'},{'id': '45', 'type': 'if_statement', 'children': ['46', '53']},{'id': '46', 'type': 'boolean_operator', 'children': ['47', '50'], 'value': 'or'},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'in'},{'id': '48', 'type': 'string', 'children': [], 'value': "' '"},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': 'in'},{'id': '51', 'type': 'string', 'children': [], 'value': "'\\t'"},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '57', 'type': 'binary_operator', 'children': ['58', '59'], 'value': '%'},{'id': '58', 'type': 'string', 'children': [], 'value': '"\'%s\'"'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '60', 'type': 'return_statement', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '62', 'type': 'function_definition', 'children': ['63', '64', '66']},{'id': '63', 'type': 'function_name', 'children': [], 'value': 'escape_new_syntax_pre_post_script'},{'id': '64', 'type': 'parameters', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'return_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'escape_new_syntax'},{'id': '70', 'type': 'argument_list', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '72', 'type': 'string', 'children': [], 'value': "'\\\\'"},{'id': '73', 'type': 'function_definition', 'children': ['74', '75', '77']},{'id': '74', 'type': 'function_name', 'children': [], 'value': 'escape_remap'},{'id': '75', 'type': 'parameters', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '77', 'type': 'block', 'children': ['78', '88', '98']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'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': 'value'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '85', 'type': 'argument_list', 'children': ['86', '87']},{'id': '86', 'type': 'string', 'children': [], 'value': "'='"},{'id': '87', 'type': 'string', 'children': [], 'value': "'\\='"},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '95', 'type': 'argument_list', 'children': ['96', '97']},{'id': '96', 'type': 'string', 'children': [], 'value': "';'"},{'id': '97', 'type': 'string', 'children': [], 'value': "'\\;'"},{'id': '98', 'type': 'return_statement', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '100', 'type': 'function_definition', 'children': ['101', '102', '105']},{'id': '101', 'type': 'function_name', 'children': [], 'value': 'join_function_template'},{'id': '102', 'type': 'parameters', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'join_string'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'escape_func'},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'return_statement', 'children': ['107']},{'id': '107', 'type': 'lambda', 'children': ['108', '110']},{'id': '108', 'type': 'lambda_parameters', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'join_string'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'list_comprehension', 'children': ['116', '120']},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'escape_func'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '120', 'type': 'for_in_clause', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '123', 'type': 'function_definition', 'children': ['124', '125', '128']},{'id': '124', 'type': 'function_name', 'children': [], 'value': 'quote_join_function_template'},{'id': '125', 'type': 'parameters', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'join_string'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'escape_func'},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'return_statement', 'children': ['130']},{'id': '130', 'type': 'lambda', 'children': ['131', '133']},{'id': '131', 'type': 'lambda_parameters', 'children': ['132']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '133', 'type': 'call', 'children': ['134', '139']},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'join_function_template'},{'id': '136', 'type': 'argument_list', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'join_string'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'escape_func'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'join_functions'},{'id': '144', 'type': 'dictionary', 'children': ['145', '152', '159']},{'id': '145', 'type': 'pair', 'children': ['146', '147']},{'id': '146', 'type': 'string', 'children': [], 'value': "'rempas'"},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'quote_join_function_template'},{'id': '149', 'type': 'argument_list', 'children': ['150', '151']},{'id': '150', 'type': 'string', 'children': [], 'value': "'; '"},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'escape_remap'},{'id': '152', 'type': 'pair', 'children': ['153', '154']},{'id': '153', 'type': 'string', 'children': [], 'value': "'arguments'"},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'quote_join_function_template'},{'id': '156', 'type': 'argument_list', 'children': ['157', '158']},{'id': '157', 'type': 'string', 'children': [], 'value': "' '"},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'escape_new_syntax'},{'id': '159', 'type': 'pair', 'children': ['160', '161']},{'id': '160', 'type': 'string', 'children': [], 'value': "'Arguments'"},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'quote_join_function_template'},{'id': '163', 'type': 'argument_list', 'children': ['164', '165']},{'id': '164', 'type': 'string', 'children': [], 'value': "' '"},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'escape_new_syntax_pre_post_script'},{'id': '166', 'type': 'if_statement', 'children': ['167', '170', '175', '184']},{'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': 'is'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '169', 'type': 'False', 'children': []},{'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': 'value'},{'id': '174', 'type': 'string', 'children': [], 'value': "'false'"},{'id': '175', 'type': 'elif_clause', 'children': ['176', '179']},{'id': '176', 'type': 'comparison_operator', 'children': ['177', '178'], 'value': 'is'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '178', 'type': 'True', 'children': []},{'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': 'value'},{'id': '183', 'type': 'string', 'children': [], 'value': "'true'"},{'id': '184', 'type': 'elif_clause', 'children': ['185', '196']},{'id': '185', 'type': 'boolean_operator', 'children': ['186', '191'], 'value': 'or'},{'id': '186', 'type': 'call', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '188', 'type': 'argument_list', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '191', 'type': 'call', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '193', 'type': 'argument_list', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '196', 'type': 'block', 'children': ['197', '205', '230']},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'join_function'},{'id': '200', 'type': 'call', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'join_function_template'},{'id': '202', 'type': 'argument_list', 'children': ['203', '204']},{'id': '203', 'type': 'string', 'children': [], 'value': "', '"},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '205', 'type': 'for_statement', 'children': ['206', '207', '215']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'join_functions'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '214', 'type': 'argument_list', 'children': []},{'id': '215', 'type': 'block', 'children': ['216']},{'id': '216', 'type': 'if_statement', 'children': ['217', '223']},{'id': '217', 'type': 'call', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '223', 'type': 'block', 'children': ['224']},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'join_function'},{'id': '227', 'type': 'subscript', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'join_functions'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'assignment', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '233', 'type': 'call', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'join_function'},{'id': '235', 'type': 'argument_list', 'children': ['236']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'assignment', 'children': ['239', '244']},{'id': '239', 'type': 'subscript', 'children': ['240', '243']},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'value'}
def set(self, attr, value): def escape_new_syntax(value, double_quote_escape='"'): value = str(value) value = value.replace("'", "''") value = value.replace('"', '%s"' % double_quote_escape) if ' ' in value or '\t' in value: value = "'%s'" % value return value def escape_new_syntax_pre_post_script(value): return escape_new_syntax(value, '\\') def escape_remap(value): value = value.replace('=', '\=') value = value.replace(';', '\;') return value def join_function_template(join_string, escape_func): return lambda value: join_string.join([escape_func(i) for i in value]) def quote_join_function_template(join_string, escape_func): return lambda value: join_function_template(join_string, escape_func)(value) join_functions = {'rempas': quote_join_function_template('; ', escape_remap), 'arguments': quote_join_function_template(' ', escape_new_syntax), 'Arguments': quote_join_function_template(' ', escape_new_syntax_pre_post_script) } if value is False: value = 'false' elif value is True: value = 'true' elif isinstance(value, list) or isinstance(value, tuple): join_function = join_function_template(', ', str) for key in list(join_functions.keys()): if attr.endswith(key): join_function = join_functions[key] value = join_function(value) self.attributes[attr] = value
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_update_status'},{'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': 'sub_job_num'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '27', '34', '49', '54', '71', '88', '105', '115', '124', '177', '183', '197', '230']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'job_id'},{'id': '12', 'type': 'conditional_expression', 'children': ['13', '20', '21'], 'value': 'if'},{'id': '13', 'type': 'binary_operator', 'children': ['14', '15'], 'value': '%'},{'id': '14', 'type': 'string', 'children': [], 'value': "'%s.%s'"},{'id': '15', 'type': 'tuple', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'cluster_id'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'sub_job_num'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'sub_job_num'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'cluster_id'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '30', 'type': 'list', 'children': ['31', '32', '33'], 'value': '[\'-format\', \'"%d"\', \'JobStatus\']'},{'id': '31', 'type': 'string', 'children': [], 'value': "'-format'"},{'id': '32', 'type': 'string', 'children': [], 'value': '\'"%d"\''},{'id': '33', 'type': 'string', 'children': [], 'value': "'JobStatus'"},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'string', 'children': [], 'value': "'condor_q {0} {1} && condor_history {0} {1}'"},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'job_id'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'string', 'children': [], 'value': "' '"},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '52', 'type': 'list', 'children': ['53'], 'value': '[cmd]'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '59']},{'id': '56', 'type': 'pattern_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': '_execute'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65', '68']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'shell'},{'id': '67', 'type': 'True', 'children': []},{'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'run_in_job_dir'},{'id': '70', 'type': 'False', 'children': []},{'id': '71', 'type': 'if_statement', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '73', 'type': 'block', 'children': ['74', '83']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '79', 'type': 'argument_list', 'children': ['80', '81', '82']},{'id': '80', 'type': 'string', 'children': [], 'value': "'Error while updating status for job %s: %s'"},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'job_id'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '83', 'type': 'raise_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'HTCondorError'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '88', 'type': 'if_statement', 'children': ['89', '91']},{'id': '89', 'type': 'not_operator', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '91', 'type': 'block', 'children': ['92', '100']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '97', 'type': 'argument_list', 'children': ['98', '99']},{'id': '98', 'type': 'string', 'children': [], 'value': "'Error while updating status for job %s: Job not found.'"},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'job_id'},{'id': '100', 'type': 'raise_statement', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'HTCondorError'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'string', 'children': [], 'value': "'Job not found.'"},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '112', 'type': 'argument_list', 'children': ['113', '114']},{'id': '113', 'type': 'string', 'children': [], 'value': '\'\\"\''},{'id': '114', 'type': 'string', 'children': [], 'value': "''"},{'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': 'log'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '120', 'type': 'argument_list', 'children': ['121', '122', '123']},{'id': '121', 'type': 'string', 'children': [], 'value': "'Job %s status: %s'"},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'job_id'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '124', 'type': 'if_statement', 'children': ['125', '127']},{'id': '125', 'type': 'not_operator', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'sub_job_num'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'if_statement', 'children': ['129', '137', '148']},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '134'], 'value': '>='},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'num_jobs'},{'id': '137', 'type': 'block', 'children': ['138']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '141', 'type': 'subscript', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '143', 'type': 'slice', 'children': ['144', '145']},{'id': '144', 'type': 'colon', 'children': []},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'num_jobs'},{'id': '148', 'type': 'else_clause', 'children': ['149']},{'id': '149', 'type': 'block', 'children': ['150', '165', '172']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'string', 'children': [], 'value': "'There are {0} sub-jobs, but {1} status(es).'"},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '157', 'type': 'argument_list', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'num_jobs'},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'out'},{'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': 'log'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '172', 'type': 'raise_statement', 'children': ['173']},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'HTCondorError'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'status_dict'},{'id': '180', 'type': 'call', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '182', 'type': 'argument_list', 'children': []},{'id': '183', 'type': 'for_statement', 'children': ['184', '185', '190']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'CONDOR_JOB_STATUSES'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '189', 'type': 'argument_list', 'children': []},{'id': '190', 'type': 'block', 'children': ['191']},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '196']},{'id': '193', 'type': 'subscript', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'status_dict'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '196', 'type': 'integer', 'children': [], 'value': '0'},{'id': '197', 'type': 'for_statement', 'children': ['198', '199', '200']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'status_code_str'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '200', 'type': 'block', 'children': ['201', '205', '218', '224']},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '204', 'type': 'integer', 'children': [], 'value': '0'},{'id': '205', 'type': 'try_statement', 'children': ['206', '214']},{'id': '206', 'type': 'block', 'children': ['207']},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '212', 'type': 'argument_list', 'children': ['213']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'status_code_str'},{'id': '214', 'type': 'except_clause', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '216', 'type': 'block', 'children': ['217']},{'id': '217', 'type': 'pass_statement', 'children': []},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'assignment', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '221', 'type': 'subscript', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'CONDOR_JOB_STATUSES'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'augmented_assignment', 'children': ['226', '229'], 'value': '+='},{'id': '226', 'type': 'subscript', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'status_dict'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '229', 'type': 'integer', 'children': [], 'value': '1'},{'id': '230', 'type': 'return_statement', 'children': ['231']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'status_dict'}
def _update_status(self, sub_job_num=None): job_id = '%s.%s' % (self.cluster_id, sub_job_num) if sub_job_num else str(self.cluster_id) format = ['-format', '"%d"', 'JobStatus'] cmd = 'condor_q {0} {1} && condor_history {0} {1}'.format(job_id, ' '.join(format)) args = [cmd] out, err = self._execute(args, shell=True, run_in_job_dir=False) if err: log.error('Error while updating status for job %s: %s', job_id, err) raise HTCondorError(err) if not out: log.error('Error while updating status for job %s: Job not found.', job_id) raise HTCondorError('Job not found.') out = out.replace('\"', '') log.info('Job %s status: %s', job_id, out) if not sub_job_num: if len(out) >= self.num_jobs: out = out[:self.num_jobs] else: msg = 'There are {0} sub-jobs, but {1} status(es).'.format(self.num_jobs, len(out)) log.error(msg) raise HTCondorError(msg) status_dict = dict() for val in CONDOR_JOB_STATUSES.values(): status_dict[val] = 0 for status_code_str in out: status_code = 0 try: status_code = int(status_code_str) except ValueError: pass key = CONDOR_JOB_STATUSES[status_code] status_dict[key] += 1 return status_dict
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'mangle'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '5', 'type': 'block', 'children': ['6', '15', '22', '28', '34', '39', '43', '47', '51', '60', '292']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'text_bytes'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'buff'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'BytesIO'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'text_bytes'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'mangled'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'BytesIO'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'last_tok'},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'INDENT'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'last_line'},{'id': '37', 'type': 'unary_operator', 'children': ['38'], 'value': '-'},{'id': '38', 'type': 'integer', 'children': [], 'value': '1'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'last_col'},{'id': '42', 'type': 'integer', 'children': [], 'value': '0'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'last_line_text'},{'id': '46', 'type': 'string', 'children': [], 'value': "''"},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'open_list_dicts'},{'id': '50', 'type': 'integer', 'children': [], 'value': '0'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'tokenizer'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'buff'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '60', 'type': 'for_statement', 'children': ['61', '71', '72']},{'id': '61', 'type': 'pattern_list', 'children': ['62', '63', '64', '67', '70']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '64', 'type': 'tuple_pattern', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'line_s'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'col_s'},{'id': '67', 'type': 'tuple_pattern', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'line_e'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'col_e'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '72', 'type': 'block', 'children': ['73', '108', '116', '128', '140', '166', '276', '280', '284', '288']},{'id': '73', 'type': 'if_statement', 'children': ['74', '82']},{'id': '74', 'type': 'boolean_operator', 'children': ['75', '78'], 'value': 'and'},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': '>'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'line_s'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'last_line'},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': '!='},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'last_line'},{'id': '80', 'type': 'unary_operator', 'children': ['81'], 'value': '-'},{'id': '81', 'type': 'integer', 'children': [], 'value': '1'},{'id': '82', 'type': 'block', 'children': ['83', '87']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'last_col'},{'id': '86', 'type': 'integer', 'children': [], 'value': '0'},{'id': '87', 'type': 'if_statement', 'children': ['88', '100']},{'id': '88', 'type': 'comparison_operator', 'children': ['89', '99'], 'value': '=='},{'id': '89', 'type': 'subscript', 'children': ['90', '95']},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'last_line_text'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'rstrip'},{'id': '94', 'type': 'argument_list', 'children': []},{'id': '95', 'type': 'slice', 'children': ['96', '98']},{'id': '96', 'type': 'unary_operator', 'children': ['97'], 'value': '-'},{'id': '97', 'type': 'integer', 'children': [], 'value': '1'},{'id': '98', 'type': 'colon', 'children': []},{'id': '99', 'type': 'string', 'children': [], 'value': "'\\\\'"},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'mangled'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'string', 'children': [], 'value': "b' \\\\\\n'"},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'striped'},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '115', 'type': 'argument_list', 'children': []},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'list_dict_open'},{'id': '119', 'type': 'list', 'children': ['120', '123', '126', '127'], 'value': "[token.LSQB, token.LBRACE, '[', '{']"},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'LSQB'},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'LBRACE'},{'id': '126', 'type': 'string', 'children': [], 'value': "'['"},{'id': '127', 'type': 'string', 'children': [], 'value': "'{'"},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'list_dict_close'},{'id': '131', 'type': 'list', 'children': ['132', '135', '138', '139'], 'value': "[token.RSQB, token.RBRACE, ']', '}']"},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'RSQB'},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'RBRACE'},{'id': '138', 'type': 'string', 'children': [], 'value': "']'"},{'id': '139', 'type': 'string', 'children': [], 'value': "'}'"},{'id': '140', 'type': 'if_statement', 'children': ['141', '148', '153']},{'id': '141', 'type': 'boolean_operator', 'children': ['142', '145'], 'value': 'or'},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': 'in'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'list_dict_open'},{'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': 'in'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'striped'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'list_dict_open'},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'augmented_assignment', 'children': ['151', '152'], 'value': '+='},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'open_list_dicts'},{'id': '152', 'type': 'integer', 'children': [], 'value': '1'},{'id': '153', 'type': 'elif_clause', 'children': ['154', '161']},{'id': '154', 'type': 'boolean_operator', 'children': ['155', '158'], 'value': 'or'},{'id': '155', 'type': 'comparison_operator', 'children': ['156', '157'], 'value': 'in'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'list_dict_close'},{'id': '158', 'type': 'comparison_operator', 'children': ['159', '160'], 'value': 'in'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'striped'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'list_dict_close'},{'id': '161', 'type': 'block', 'children': ['162']},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'augmented_assignment', 'children': ['164', '165'], 'value': '-='},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'open_list_dicts'},{'id': '165', 'type': 'integer', 'children': [], 'value': '1'},{'id': '166', 'type': 'if_statement', 'children': ['167', '209', '230', '238']},{'id': '167', 'type': 'boolean_operator', 'children': ['168', '173'], 'value': 'and'},{'id': '168', 'type': 'comparison_operator', 'children': ['169', '170'], 'value': '=='},{'id': '169', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'STRING'},{'id': '173', 'type': '()', 'children': ['174']},{'id': '174', 'type': 'boolean_operator', 'children': ['175', '180'], 'value': 'or'},{'id': '175', 'type': 'comparison_operator', 'children': ['176', '177'], 'value': '=='},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'last_tok'},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'INDENT'},{'id': '180', 'type': '()', 'children': ['181']},{'id': '181', 'type': 'boolean_operator', 'children': ['182', '206'], 'value': 'and'},{'id': '182', 'type': '()', 'children': ['183']},{'id': '183', 'type': 'boolean_operator', 'children': ['184', '201'], 'value': 'or'},{'id': '184', 'type': 'boolean_operator', 'children': ['185', '196'], 'value': 'or'},{'id': '185', 'type': 'boolean_operator', 'children': ['186', '191'], 'value': 'or'},{'id': '186', 'type': 'comparison_operator', 'children': ['187', '188'], 'value': '=='},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'last_tok'},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'NEWLINE'},{'id': '191', 'type': 'comparison_operator', 'children': ['192', '193'], 'value': '=='},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'last_tok'},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'tokenize'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'NL'},{'id': '196', 'type': 'comparison_operator', 'children': ['197', '198'], 'value': '=='},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'last_tok'},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'DEDENT'},{'id': '201', 'type': 'comparison_operator', 'children': ['202', '203'], 'value': '=='},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'last_tok'},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'tokenize'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'ENCODING'},{'id': '206', 'type': 'comparison_operator', 'children': ['207', '208'], 'value': '=='},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'open_list_dicts'},{'id': '208', 'type': 'integer', 'children': [], 'value': '0'},{'id': '209', 'type': 'block', 'children': ['210']},{'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': 'mangled'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'binary_operator', 'children': ['217', '218'], 'value': '*'},{'id': '217', 'type': 'string', 'children': [], 'value': "b'\\n'"},{'id': '218', 'type': '()', 'children': ['219']},{'id': '219', 'type': 'binary_operator', 'children': ['220', '229'], 'value': '-'},{'id': '220', 'type': 'call', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'call', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '229', 'type': 'integer', 'children': [], 'value': '1'},{'id': '230', 'type': 'elif_clause', 'children': ['231', '236']},{'id': '231', 'type': 'comparison_operator', 'children': ['232', '233'], 'value': '=='},{'id': '232', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'tokenize'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'COMMENT'},{'id': '236', 'type': 'block', 'children': ['237']},{'id': '237', 'type': 'pass_statement', 'children': []},{'id': '238', 'type': 'else_clause', 'children': ['239']},{'id': '239', 'type': 'block', 'children': ['240', '257']},{'id': '240', 'type': 'if_statement', 'children': ['241', '244']},{'id': '241', 'type': 'comparison_operator', 'children': ['242', '243'], 'value': '>'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'col_s'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'last_col'},{'id': '244', 'type': 'block', 'children': ['245']},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'call', 'children': ['247', '250']},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'mangled'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'binary_operator', 'children': ['252', '253'], 'value': '*'},{'id': '252', 'type': 'string', 'children': [], 'value': "b' '"},{'id': '253', 'type': '()', 'children': ['254']},{'id': '254', 'type': 'binary_operator', 'children': ['255', '256'], 'value': '-'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'col_s'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'last_col'},{'id': '257', 'type': 'if_statement', 'children': ['258', '263']},{'id': '258', 'type': 'comparison_operator', 'children': ['259', '260'], 'value': '!='},{'id': '259', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '260', 'type': 'attribute', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'tokenize'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'ENCODING'},{'id': '263', 'type': 'block', 'children': ['264']},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'call', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'mangled'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'call', 'children': ['271', '274']},{'id': '271', 'type': 'attribute', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '274', 'type': 'argument_list', 'children': ['275']},{'id': '275', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '276', 'type': 'expression_statement', 'children': ['277']},{'id': '277', 'type': 'assignment', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'last_tok'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '280', 'type': 'expression_statement', 'children': ['281']},{'id': '281', 'type': 'assignment', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'last_col'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'col_e'},{'id': '284', 'type': 'expression_statement', 'children': ['285']},{'id': '285', 'type': 'assignment', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'last_line'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'line_e'},{'id': '288', 'type': 'expression_statement', 'children': ['289']},{'id': '289', 'type': 'assignment', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'last_line_text'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '292', 'type': 'return_statement', 'children': ['293']},{'id': '293', 'type': 'call', 'children': ['294', '301']},{'id': '294', 'type': 'attribute', 'children': ['295', '300']},{'id': '295', 'type': 'call', 'children': ['296', '299']},{'id': '296', 'type': 'attribute', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'mangled'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'getvalue'},{'id': '299', 'type': 'argument_list', 'children': []},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '301', 'type': 'argument_list', 'children': ['302']},{'id': '302', 'type': 'string', 'children': [], 'value': "'utf-8'"}
def mangle(text): text_bytes = text.encode('utf-8') buff = BytesIO(text_bytes) mangled = BytesIO() last_tok = token.INDENT last_line = -1 last_col = 0 last_line_text = '' open_list_dicts = 0 tokens = tokenizer(buff.readline) for t, text, (line_s, col_s), (line_e, col_e), line in tokens: if line_s > last_line and last_line != -1: last_col = 0 if last_line_text.rstrip()[-1:] == '\\': mangled.write(b' \\\n') striped = text.strip() list_dict_open = [token.LSQB, token.LBRACE, '[', '{'] list_dict_close = [token.RSQB, token.RBRACE, ']', '}'] if t in list_dict_open or striped in list_dict_open: open_list_dicts += 1 elif t in list_dict_close or striped in list_dict_close: open_list_dicts -= 1 if t == token.STRING and (last_tok == token.INDENT or ( (last_tok == token.NEWLINE or last_tok == tokenize.NL or last_tok == token.DEDENT or last_tok == tokenize.ENCODING) and open_list_dicts == 0)): mangled.write(b'\n' * (len(text.split('\n')) - 1)) elif t == tokenize.COMMENT: pass else: if col_s > last_col: mangled.write(b' ' * (col_s - last_col)) if t != tokenize.ENCODING: mangled.write(text.encode('utf-8')) last_tok = t last_col = col_e last_line = line_e last_line_text = line return mangled.getvalue().decode('utf-8')