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': '_partition_tasks'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'worker'},{'id': '5', 'type': 'block', 'children': ['6', '12', '27', '31', '52', '79', '96', '108', '125', '157', '188', '196', '204', '212', '220', '228', '236']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'task_history'},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'worker'},{'id': '11', 'type': 'identifier', 'children': [], 'value': '_add_task_history'},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'pending_tasks'},{'id': '15', 'type': 'set_comprehension', 'children': ['16', '17', '23']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '17', 'type': 'for_in_clause', 'children': ['18', '22']},{'id': '18', 'type': 'tuple_pattern', 'children': ['19', '20', '21']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'task_history'},{'id': '23', 'type': 'if_clause', 'children': ['24']},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': '=='},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '26', 'type': 'string', 'children': [], 'value': "'PENDING'"},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'set_tasks'},{'id': '30', 'type': 'dictionary', 'children': []},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '36']},{'id': '33', 'type': 'subscript', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'set_tasks'},{'id': '35', 'type': 'string', 'children': [], 'value': '"completed"'},{'id': '36', 'type': 'set_comprehension', 'children': ['37', '38', '44']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '38', 'type': 'for_in_clause', 'children': ['39', '43']},{'id': '39', 'type': 'tuple_pattern', 'children': ['40', '41', '42']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'task_history'},{'id': '44', 'type': 'if_clause', 'children': ['45']},{'id': '45', 'type': 'boolean_operator', 'children': ['46', '49'], 'value': 'and'},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': '=='},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '48', 'type': 'string', 'children': [], 'value': "'DONE'"},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'in'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'pending_tasks'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '57']},{'id': '54', 'type': 'subscript', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'set_tasks'},{'id': '56', 'type': 'string', 'children': [], 'value': '"already_done"'},{'id': '57', 'type': 'set_comprehension', 'children': ['58', '59', '65']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '59', 'type': 'for_in_clause', 'children': ['60', '64']},{'id': '60', 'type': 'tuple_pattern', 'children': ['61', '62', '63']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'task_history'},{'id': '65', 'type': 'if_clause', 'children': ['66']},{'id': '66', 'type': 'boolean_operator', 'children': ['67', '74'], 'value': 'and'},{'id': '67', 'type': 'boolean_operator', 'children': ['68', '71'], 'value': 'and'},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': '=='},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '70', 'type': 'string', 'children': [], 'value': "'DONE'"},{'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': 'not'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'pending_tasks'},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '76'], 'value': 'not'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'set_tasks'},{'id': '78', 'type': 'string', 'children': [], 'value': '"completed"'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '84']},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'set_tasks'},{'id': '83', 'type': 'string', 'children': [], 'value': '"ever_failed"'},{'id': '84', 'type': 'set_comprehension', 'children': ['85', '86', '92']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '86', 'type': 'for_in_clause', 'children': ['87', '91']},{'id': '87', 'type': 'tuple_pattern', 'children': ['88', '89', '90']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'task_history'},{'id': '92', 'type': 'if_clause', 'children': ['93']},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': '=='},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '95', 'type': 'string', 'children': [], 'value': "'FAILED'"},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '101']},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'set_tasks'},{'id': '100', 'type': 'string', 'children': [], 'value': '"failed"'},{'id': '101', 'type': 'binary_operator', 'children': ['102', '105'], 'value': '-'},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'set_tasks'},{'id': '104', 'type': 'string', 'children': [], 'value': '"ever_failed"'},{'id': '105', 'type': 'subscript', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'set_tasks'},{'id': '107', 'type': 'string', 'children': [], 'value': '"completed"'},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '113']},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'set_tasks'},{'id': '112', 'type': 'string', 'children': [], 'value': '"scheduling_error"'},{'id': '113', 'type': 'set_comprehension', 'children': ['114', '115', '121']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '115', 'type': 'for_in_clause', 'children': ['116', '120']},{'id': '116', 'type': 'tuple_pattern', 'children': ['117', '118', '119']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'task_history'},{'id': '121', 'type': 'if_clause', 'children': ['122']},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': '=='},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '124', 'type': 'string', 'children': [], 'value': "'UNKNOWN'"},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '130']},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'set_tasks'},{'id': '129', 'type': 'string', 'children': [], 'value': '"still_pending_ext"'},{'id': '130', 'type': 'set_comprehension', 'children': ['131', '132', '138']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '132', 'type': 'for_in_clause', 'children': ['133', '137']},{'id': '133', 'type': 'tuple_pattern', 'children': ['134', '135', '136']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'task_history'},{'id': '138', 'type': 'if_clause', 'children': ['139']},{'id': '139', 'type': 'boolean_operator', 'children': ['140', '155'], 'value': 'and'},{'id': '140', 'type': 'boolean_operator', 'children': ['141', '150'], 'value': 'and'},{'id': '141', 'type': 'boolean_operator', 'children': ['142', '145'], 'value': 'and'},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': '=='},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '144', 'type': 'string', 'children': [], 'value': "'PENDING'"},{'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': 'not'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '147', 'type': 'subscript', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'set_tasks'},{'id': '149', 'type': 'string', 'children': [], 'value': '"ever_failed"'},{'id': '150', 'type': 'comparison_operator', 'children': ['151', '152'], 'value': 'not'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'set_tasks'},{'id': '154', 'type': 'string', 'children': [], 'value': '"completed"'},{'id': '155', 'type': 'not_operator', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '162']},{'id': '159', 'type': 'subscript', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'set_tasks'},{'id': '161', 'type': 'string', 'children': [], 'value': '"still_pending_not_ext"'},{'id': '162', 'type': 'set_comprehension', 'children': ['163', '164', '170']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '164', 'type': 'for_in_clause', 'children': ['165', '169']},{'id': '165', 'type': 'tuple_pattern', 'children': ['166', '167', '168']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'task_history'},{'id': '170', 'type': 'if_clause', 'children': ['171']},{'id': '171', 'type': 'boolean_operator', 'children': ['172', '187'], 'value': 'and'},{'id': '172', 'type': 'boolean_operator', 'children': ['173', '182'], 'value': 'and'},{'id': '173', 'type': 'boolean_operator', 'children': ['174', '177'], 'value': 'and'},{'id': '174', 'type': 'comparison_operator', 'children': ['175', '176'], 'value': '=='},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '176', 'type': 'string', 'children': [], 'value': "'PENDING'"},{'id': '177', 'type': 'comparison_operator', 'children': ['178', '179'], 'value': 'not'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '179', 'type': 'subscript', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'set_tasks'},{'id': '181', 'type': 'string', 'children': [], 'value': '"ever_failed"'},{'id': '182', 'type': 'comparison_operator', 'children': ['183', '184'], 'value': 'not'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '184', 'type': 'subscript', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'set_tasks'},{'id': '186', 'type': 'string', 'children': [], 'value': '"completed"'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '193']},{'id': '190', 'type': 'subscript', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'set_tasks'},{'id': '192', 'type': 'string', 'children': [], 'value': '"run_by_other_worker"'},{'id': '193', 'type': 'call', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '195', 'type': 'argument_list', 'children': []},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '201']},{'id': '198', 'type': 'subscript', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'set_tasks'},{'id': '200', 'type': 'string', 'children': [], 'value': '"upstream_failure"'},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '203', 'type': 'argument_list', 'children': []},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '209']},{'id': '206', 'type': 'subscript', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'set_tasks'},{'id': '208', 'type': 'string', 'children': [], 'value': '"upstream_missing_dependency"'},{'id': '209', 'type': 'call', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '211', 'type': 'argument_list', 'children': []},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '217']},{'id': '214', 'type': 'subscript', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'set_tasks'},{'id': '216', 'type': 'string', 'children': [], 'value': '"upstream_run_by_other_worker"'},{'id': '217', 'type': 'call', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '219', 'type': 'argument_list', 'children': []},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'assignment', 'children': ['222', '225']},{'id': '222', 'type': 'subscript', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'set_tasks'},{'id': '224', 'type': 'string', 'children': [], 'value': '"upstream_scheduling_error"'},{'id': '225', 'type': 'call', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '227', 'type': 'argument_list', 'children': []},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '233']},{'id': '230', 'type': 'subscript', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'set_tasks'},{'id': '232', 'type': 'string', 'children': [], 'value': '"not_run"'},{'id': '233', 'type': 'call', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '235', 'type': 'argument_list', 'children': []},{'id': '236', 'type': 'return_statement', 'children': ['237']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'set_tasks'} | def _partition_tasks(worker):
task_history = worker._add_task_history
pending_tasks = {task for(task, status, ext) in task_history if status == 'PENDING'}
set_tasks = {}
set_tasks["completed"] = {task for (task, status, ext) in task_history if status == 'DONE' and task in pending_tasks}
set_tasks["already_done"] = {task for (task, status, ext) in task_history
if status == 'DONE' and task not in pending_tasks and task not in set_tasks["completed"]}
set_tasks["ever_failed"] = {task for (task, status, ext) in task_history if status == 'FAILED'}
set_tasks["failed"] = set_tasks["ever_failed"] - set_tasks["completed"]
set_tasks["scheduling_error"] = {task for(task, status, ext) in task_history if status == 'UNKNOWN'}
set_tasks["still_pending_ext"] = {task for (task, status, ext) in task_history
if status == 'PENDING' and task not in set_tasks["ever_failed"] and task not in set_tasks["completed"] and not ext}
set_tasks["still_pending_not_ext"] = {task for (task, status, ext) in task_history
if status == 'PENDING' and task not in set_tasks["ever_failed"] and task not in set_tasks["completed"] and ext}
set_tasks["run_by_other_worker"] = set()
set_tasks["upstream_failure"] = set()
set_tasks["upstream_missing_dependency"] = set()
set_tasks["upstream_run_by_other_worker"] = set()
set_tasks["upstream_scheduling_error"] = set()
set_tasks["not_run"] = set()
return set_tasks |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_serve_runs'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '6', 'type': 'block', 'children': ['7', '99']},{'id': '7', 'type': 'if_statement', 'children': ['8', '11', '39']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': '_db_connection_provider'},{'id': '11', 'type': 'block', 'children': ['12', '20', '29']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_db_connection_provider'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'string', 'children': [], 'value': "'''\n SELECT\n run_name,\n started_time IS NULL as started_time_nulls_last,\n started_time\n FROM Runs\n ORDER BY started_time_nulls_last, started_time, run_name\n '''"},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'run_names'},{'id': '32', 'type': 'list_comprehension', 'children': ['33', '36']},{'id': '33', 'type': 'subscript', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '35', 'type': 'integer', 'children': [], 'value': '0'},{'id': '36', 'type': 'for_in_clause', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '39', 'type': 'else_clause', 'children': ['40']},{'id': '40', 'type': 'block', 'children': ['41', '54', '90']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'run_names'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '53']},{'id': '48', 'type': 'attribute', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': '_multiplexer'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'Runs'},{'id': '53', 'type': 'argument_list', 'children': []},{'id': '54', 'type': 'function_definition', 'children': ['55', '56', '58']},{'id': '55', 'type': 'function_name', 'children': [], 'value': 'get_first_event_timestamp'},{'id': '56', 'type': 'parameters', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'run_name'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'try_statement', 'children': ['60', '70']},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'return_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '68']},{'id': '63', 'type': 'attribute', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': '_multiplexer'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'FirstEventTimestamp'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'run_name'},{'id': '70', 'type': 'except_clause', 'children': ['71', '75']},{'id': '71', 'type': 'as_pattern', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '73', 'type': 'as_pattern_target', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '75', 'type': 'block', 'children': ['76', '85']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '81', 'type': 'argument_list', 'children': ['82', '83', '84']},{'id': '82', 'type': 'string', 'children': [], 'value': "'Unable to get first event timestamp for run %s: %s'"},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'run_name'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '85', 'type': 'return_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'string', 'children': [], 'value': "'inf'"},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'run_names'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'get_first_event_timestamp'},{'id': '99', 'type': 'return_statement', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'http_util'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'Respond'},{'id': '104', 'type': 'argument_list', 'children': ['105', '106', '107']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'run_names'},{'id': '107', 'type': 'string', 'children': [], 'value': "'application/json'"} | def _serve_runs(self, request):
if self._db_connection_provider:
db = self._db_connection_provider()
cursor = db.execute('''
SELECT
run_name,
started_time IS NULL as started_time_nulls_last,
started_time
FROM Runs
ORDER BY started_time_nulls_last, started_time, run_name
''')
run_names = [row[0] for row in cursor]
else:
run_names = sorted(self._multiplexer.Runs())
def get_first_event_timestamp(run_name):
try:
return self._multiplexer.FirstEventTimestamp(run_name)
except ValueError as e:
logger.warn(
'Unable to get first event timestamp for run %s: %s', run_name, e)
return float('inf')
run_names.sort(key=get_first_event_timestamp)
return http_util.Respond(request, run_names, 'application/json') |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_fetch_events_files_on_disk'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '21', '36']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'all_files'},{'id': '9', 'type': 'call', 'children': ['10', '17']},{'id': '10', 'type': 'attribute', 'children': ['11', '16']},{'id': '11', 'type': 'attribute', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'tf'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'io'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'gfile'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'listdir'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_events_directory'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'relevant_files'},{'id': '24', 'type': 'list_comprehension', 'children': ['25', '26', '29']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'file_name'},{'id': '26', 'type': 'for_in_clause', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'file_name'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'all_files'},{'id': '29', 'type': 'if_clause', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': '_DEBUGGER_EVENTS_FILE_NAME_REGEX'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'file_name'},{'id': '36', 'type': 'return_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'relevant_files'},{'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': '_obtain_file_index'} | def _fetch_events_files_on_disk(self):
all_files = tf.io.gfile.listdir(self._events_directory)
relevant_files = [
file_name for file_name in all_files
if _DEBUGGER_EVENTS_FILE_NAME_REGEX.match(file_name)
]
return sorted(relevant_files, key=self._obtain_file_index) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'Cleanse'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '7', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'if_statement', 'children': ['10', '15', '18', '53', '70', '89', '109', '138']},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '12', 'type': 'argument_list', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'return_statement', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '18', 'type': 'elif_clause', 'children': ['19', '24']},{'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': 'obj'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'if_statement', 'children': ['26', '29', '32', '39', '49']},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': '=='},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '28', 'type': 'identifier', 'children': [], 'value': '_INFINITY'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'return_statement', 'children': ['31']},{'id': '31', 'type': 'string', 'children': [], 'value': "'Infinity'"},{'id': '32', 'type': 'elif_clause', 'children': ['33', '36']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': '=='},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_NEGATIVE_INFINITY'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'return_statement', 'children': ['38']},{'id': '38', 'type': 'string', 'children': [], 'value': "'-Infinity'"},{'id': '39', 'type': 'elif_clause', 'children': ['40', '46']},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'math'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'isnan'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'return_statement', 'children': ['48']},{'id': '48', 'type': 'string', 'children': [], 'value': "'NaN'"},{'id': '49', 'type': 'else_clause', 'children': ['50']},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'return_statement', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '53', 'type': 'elif_clause', 'children': ['54', '59']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'return_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': 'tf'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'compat'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'as_text'},{'id': '67', 'type': 'argument_list', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '70', 'type': 'elif_clause', 'children': ['71', '78']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '75', 'type': 'tuple', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'return_statement', 'children': ['80']},{'id': '80', 'type': 'list_comprehension', 'children': ['81', '86']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'Cleanse'},{'id': '83', 'type': 'argument_list', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '86', 'type': 'for_in_clause', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '89', 'type': 'elif_clause', 'children': ['90', '95']},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '92', 'type': 'argument_list', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'return_statement', 'children': ['97']},{'id': '97', 'type': 'list_comprehension', 'children': ['98', '103']},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'Cleanse'},{'id': '100', 'type': 'argument_list', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '103', 'type': 'for_in_clause', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '109', 'type': 'elif_clause', 'children': ['110', '115']},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '112', 'type': 'argument_list', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '115', 'type': 'block', 'children': ['116']},{'id': '116', 'type': 'return_statement', 'children': ['117']},{'id': '117', 'type': 'dictionary_comprehension', 'children': ['118', '129']},{'id': '118', 'type': 'pair', 'children': ['119', '124']},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'Cleanse'},{'id': '121', 'type': 'argument_list', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'Cleanse'},{'id': '126', 'type': 'argument_list', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '129', 'type': 'for_in_clause', 'children': ['130', '133']},{'id': '130', 'type': 'pattern_list', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '137', 'type': 'argument_list', 'children': []},{'id': '138', 'type': 'else_clause', 'children': ['139']},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'return_statement', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'obj'} | def Cleanse(obj, encoding='utf-8'):
if isinstance(obj, int):
return obj
elif isinstance(obj, float):
if obj == _INFINITY:
return 'Infinity'
elif obj == _NEGATIVE_INFINITY:
return '-Infinity'
elif math.isnan(obj):
return 'NaN'
else:
return obj
elif isinstance(obj, bytes):
return tf.compat.as_text(obj, encoding)
elif isinstance(obj, (list, tuple)):
return [Cleanse(i, encoding) for i in obj]
elif isinstance(obj, set):
return [Cleanse(i, encoding) for i in sorted(obj)]
elif isinstance(obj, dict):
return {Cleanse(k, encoding): Cleanse(v, encoding) for k, v in obj.items()}
else:
return obj |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'session_groups'},{'id': '6', 'type': 'block', 'children': ['7', '21']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'session_groups'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'keyword_argument', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'attrgetter'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '21', 'type': 'for_statement', 'children': ['22', '25', '42']},{'id': '22', 'type': 'pattern_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'col_param'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'extractor'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'reversed'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '33', 'type': 'argument_list', 'children': ['34', '39']},{'id': '34', 'type': 'attribute', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': '_request'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'col_params'},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': '_extractors'},{'id': '42', 'type': 'block', 'children': ['43', '53']},{'id': '43', 'type': 'if_statement', 'children': ['44', '51']},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '48'], 'value': '=='},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'col_param'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'api_pb2'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'ORDER_UNSPECIFIED'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'continue_statement', 'children': []},{'id': '53', 'type': 'if_statement', 'children': ['54', '61', '80', '109']},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '58'], 'value': '=='},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'col_param'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'api_pb2'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ORDER_ASC'},{'id': '61', 'type': 'block', 'children': ['62']},{'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': 'session_groups'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': '_create_key_func'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'extractor'},{'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'none_is_largest'},{'id': '76', 'type': 'not_operator', 'children': ['77']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'col_param'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'missing_values_first'},{'id': '80', 'type': 'elif_clause', 'children': ['81', '88']},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '85'], 'value': '=='},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'col_param'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'api_pb2'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'ORDER_DESC'},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'session_groups'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '94', 'type': 'argument_list', 'children': ['95', '106']},{'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': '_create_key_func'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'extractor'},{'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'none_is_largest'},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'col_param'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'missing_values_first'},{'id': '106', 'type': 'keyword_argument', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '108', 'type': 'True', 'children': []},{'id': '109', 'type': 'else_clause', 'children': ['110']},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'raise_statement', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'HParamsError'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'binary_operator', 'children': ['118', '119'], 'value': '%'},{'id': '118', 'type': 'string', 'children': [], 'value': "'Unknown col_param.order given: %s'"},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'col_param'} | def _sort(self, session_groups):
session_groups.sort(key=operator.attrgetter('name'))
for col_param, extractor in reversed(list(zip(self._request.col_params,
self._extractors))):
if col_param.order == api_pb2.ORDER_UNSPECIFIED:
continue
if col_param.order == api_pb2.ORDER_ASC:
session_groups.sort(
key=_create_key_func(
extractor,
none_is_largest=not col_param.missing_values_first))
elif col_param.order == api_pb2.ORDER_DESC:
session_groups.sort(
key=_create_key_func(
extractor,
none_is_largest=col_param.missing_values_first),
reverse=True)
else:
raise error.HParamsError('Unknown col_param.order given: %s' %
col_param) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '6', 'type': 'block', 'children': ['7', '24']},{'id': '7', 'type': 'if_statement', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': '_sort'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'list_splat', 'children': ['21']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': '_sort'},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'search'} | def sort(self, search):
if self._sort:
search = search.sort(*self._sort)
return search |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'competitions_list'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '16', 'type': 'integer', 'children': [], 'value': '1'},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'block', 'children': ['21', '28', '45', '56', '73', '83', '100', '136']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'valid_groups'},{'id': '24', 'type': 'list', 'children': ['25', '26', '27'], 'value': "['general', 'entered', 'inClass']"},{'id': '25', 'type': 'string', 'children': [], 'value': "'general'"},{'id': '26', 'type': 'string', 'children': [], 'value': "'entered'"},{'id': '27', 'type': 'string', 'children': [], 'value': "'inClass'"},{'id': '28', 'type': 'if_statement', 'children': ['29', '34']},{'id': '29', 'type': 'boolean_operator', 'children': ['30', '31'], 'value': 'and'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'not'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'valid_groups'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'raise_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'binary_operator', 'children': ['40', '41'], 'value': '+'},{'id': '40', 'type': 'string', 'children': [], 'value': "'Invalid group specified. Valid options are '"},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'valid_groups'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'valid_categories'},{'id': '48', 'type': 'list', 'children': ['49', '50', '51', '52', '53', '54', '55'], 'value': "[\n 'all', 'featured', 'research', 'recruitment', 'gettingStarted',\n 'masters', 'playground'\n ]"},{'id': '49', 'type': 'string', 'children': [], 'value': "'all'"},{'id': '50', 'type': 'string', 'children': [], 'value': "'featured'"},{'id': '51', 'type': 'string', 'children': [], 'value': "'research'"},{'id': '52', 'type': 'string', 'children': [], 'value': "'recruitment'"},{'id': '53', 'type': 'string', 'children': [], 'value': "'gettingStarted'"},{'id': '54', 'type': 'string', 'children': [], 'value': "'masters'"},{'id': '55', 'type': 'string', 'children': [], 'value': "'playground'"},{'id': '56', 'type': 'if_statement', 'children': ['57', '62']},{'id': '57', 'type': 'boolean_operator', 'children': ['58', '59'], 'value': 'and'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': 'not'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'valid_categories'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'raise_statement', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'binary_operator', 'children': ['68', '69'], 'value': '+'},{'id': '68', 'type': 'string', 'children': [], 'value': "'Invalid category specified. Valid options are '"},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'valid_categories'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'valid_sort_by'},{'id': '76', 'type': 'list', 'children': ['77', '78', '79', '80', '81', '82'], 'value': "[\n 'grouped', 'prize', 'earliestDeadline', 'latestDeadline',\n 'numberOfTeams', 'recentlyCreated'\n ]"},{'id': '77', 'type': 'string', 'children': [], 'value': "'grouped'"},{'id': '78', 'type': 'string', 'children': [], 'value': "'prize'"},{'id': '79', 'type': 'string', 'children': [], 'value': "'earliestDeadline'"},{'id': '80', 'type': 'string', 'children': [], 'value': "'latestDeadline'"},{'id': '81', 'type': 'string', 'children': [], 'value': "'numberOfTeams'"},{'id': '82', 'type': 'string', 'children': [], 'value': "'recentlyCreated'"},{'id': '83', 'type': 'if_statement', 'children': ['84', '89']},{'id': '84', 'type': 'boolean_operator', 'children': ['85', '86'], 'value': 'and'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': 'not'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'valid_sort_by'},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'raise_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '+'},{'id': '95', 'type': 'string', 'children': [], 'value': "'Invalid sort_by specified. Valid options are '"},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'valid_sort_by'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'competitions_list_result'},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'process_response'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'competitions_list_with_http_info'},{'id': '112', 'type': 'argument_list', 'children': ['113', '118', '123', '128', '131']},{'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '115', 'type': 'boolean_operator', 'children': ['116', '117'], 'value': 'or'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '117', 'type': 'string', 'children': [], 'value': "''"},{'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '120', 'type': 'boolean_operator', 'children': ['121', '122'], 'value': 'or'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '122', 'type': 'string', 'children': [], 'value': "''"},{'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '125', 'type': 'boolean_operator', 'children': ['126', '127'], 'value': 'or'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '127', 'type': 'string', 'children': [], 'value': "''"},{'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '131', 'type': 'keyword_argument', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '133', 'type': 'boolean_operator', 'children': ['134', '135'], 'value': 'or'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '135', 'type': 'string', 'children': [], 'value': "''"},{'id': '136', 'type': 'return_statement', 'children': ['137']},{'id': '137', 'type': 'list_comprehension', 'children': ['138', '142']},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'Competition'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '142', 'type': 'for_in_clause', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'competitions_list_result'} | def competitions_list(self,
group=None,
category=None,
sort_by=None,
page=1,
search=None):
valid_groups = ['general', 'entered', 'inClass']
if group and group not in valid_groups:
raise ValueError('Invalid group specified. Valid options are ' +
str(valid_groups))
valid_categories = [
'all', 'featured', 'research', 'recruitment', 'gettingStarted',
'masters', 'playground'
]
if category and category not in valid_categories:
raise ValueError('Invalid category specified. Valid options are ' +
str(valid_categories))
valid_sort_by = [
'grouped', 'prize', 'earliestDeadline', 'latestDeadline',
'numberOfTeams', 'recentlyCreated'
]
if sort_by and sort_by not in valid_sort_by:
raise ValueError('Invalid sort_by specified. Valid options are ' +
str(valid_sort_by))
competitions_list_result = self.process_response(
self.competitions_list_with_http_info(
group=group or '',
category=category or '',
sort_by=sort_by or '',
page=page,
search=search or ''))
return [Competition(c) for c in competitions_list_result] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'competitions_list_cli'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '16', 'type': 'integer', 'children': [], 'value': '1'},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'csv_display'},{'id': '22', 'type': 'False', 'children': []},{'id': '23', 'type': 'block', 'children': ['24', '47', '57']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'competitions'},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'competitions_list'},{'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': 'group'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'group'},{'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': 'sort_by'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '50', 'type': 'list', 'children': ['51', '52', '53', '54', '55', '56'], 'value': "[\n 'ref', 'deadline', 'category', 'reward', 'teamCount',\n 'userHasEntered'\n ]"},{'id': '51', 'type': 'string', 'children': [], 'value': "'ref'"},{'id': '52', 'type': 'string', 'children': [], 'value': "'deadline'"},{'id': '53', 'type': 'string', 'children': [], 'value': "'category'"},{'id': '54', 'type': 'string', 'children': [], 'value': "'reward'"},{'id': '55', 'type': 'string', 'children': [], 'value': "'teamCount'"},{'id': '56', 'type': 'string', 'children': [], 'value': "'userHasEntered'"},{'id': '57', 'type': 'if_statement', 'children': ['58', '59', '81']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'competitions'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'if_statement', 'children': ['61', '62', '71']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'csv_display'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'print_csv'},{'id': '68', 'type': 'argument_list', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'competitions'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '71', 'type': 'else_clause', 'children': ['72']},{'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': 'self'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'print_table'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'competitions'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '81', 'type': 'else_clause', 'children': ['82']},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'string', 'children': [], 'value': "'No competitions found'"} | def competitions_list_cli(self,
group=None,
category=None,
sort_by=None,
page=1,
search=None,
csv_display=False):
competitions = self.competitions_list(
group=group,
category=category,
sort_by=sort_by,
page=page,
search=search)
fields = [
'ref', 'deadline', 'category', 'reward', 'teamCount',
'userHasEntered'
]
if competitions:
if csv_display:
self.print_csv(competitions, fields)
else:
self.print_table(competitions, fields)
else:
print('No competitions found') |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '32']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'dataset_list'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'file_type'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'license_name'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'tag_ids'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'mine'},{'id': '28', 'type': 'False', 'children': []},{'id': '29', 'type': 'default_parameter', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '31', 'type': 'integer', 'children': [], 'value': '1'},{'id': '32', 'type': 'block', 'children': ['33', '42', '59', '67', '84', '93', '110', '119', '136', '149', '153', '168', '175', '229']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'valid_sort_bys'},{'id': '36', 'type': 'list', 'children': ['37', '38', '39', '40', '41'], 'value': "['hottest', 'votes', 'updated', 'active', 'published']"},{'id': '37', 'type': 'string', 'children': [], 'value': "'hottest'"},{'id': '38', 'type': 'string', 'children': [], 'value': "'votes'"},{'id': '39', 'type': 'string', 'children': [], 'value': "'updated'"},{'id': '40', 'type': 'string', 'children': [], 'value': "'active'"},{'id': '41', 'type': 'string', 'children': [], 'value': "'published'"},{'id': '42', 'type': 'if_statement', 'children': ['43', '48']},{'id': '43', 'type': 'boolean_operator', 'children': ['44', '45'], 'value': 'and'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': 'not'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'valid_sort_bys'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'raise_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'binary_operator', 'children': ['54', '55'], 'value': '+'},{'id': '54', 'type': 'string', 'children': [], 'value': "'Invalid sort by specified. Valid options are '"},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'valid_sort_bys'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'valid_sizes'},{'id': '62', 'type': 'list', 'children': ['63', '64', '65', '66'], 'value': "['all', 'small', 'medium', 'large']"},{'id': '63', 'type': 'string', 'children': [], 'value': "'all'"},{'id': '64', 'type': 'string', 'children': [], 'value': "'small'"},{'id': '65', 'type': 'string', 'children': [], 'value': "'medium'"},{'id': '66', 'type': 'string', 'children': [], 'value': "'large'"},{'id': '67', 'type': 'if_statement', 'children': ['68', '73']},{'id': '68', 'type': 'boolean_operator', 'children': ['69', '70'], 'value': 'and'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': 'not'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'valid_sizes'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'raise_statement', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'binary_operator', 'children': ['79', '80'], 'value': '+'},{'id': '79', 'type': 'string', 'children': [], 'value': "'Invalid size specified. Valid options are '"},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'valid_sizes'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'valid_file_types'},{'id': '87', 'type': 'list', 'children': ['88', '89', '90', '91', '92'], 'value': "['all', 'csv', 'sqlite', 'json', 'bigQuery']"},{'id': '88', 'type': 'string', 'children': [], 'value': "'all'"},{'id': '89', 'type': 'string', 'children': [], 'value': "'csv'"},{'id': '90', 'type': 'string', 'children': [], 'value': "'sqlite'"},{'id': '91', 'type': 'string', 'children': [], 'value': "'json'"},{'id': '92', 'type': 'string', 'children': [], 'value': "'bigQuery'"},{'id': '93', 'type': 'if_statement', 'children': ['94', '99']},{'id': '94', 'type': 'boolean_operator', 'children': ['95', '96'], 'value': 'and'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'file_type'},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': 'not'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'file_type'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'valid_file_types'},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'raise_statement', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'binary_operator', 'children': ['105', '106'], 'value': '+'},{'id': '105', 'type': 'string', 'children': [], 'value': "'Invalid file type specified. Valid options are '"},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'valid_file_types'},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'valid_license_names'},{'id': '113', 'type': 'list', 'children': ['114', '115', '116', '117', '118'], 'value': "['all', 'cc', 'gpl', 'odb', 'other']"},{'id': '114', 'type': 'string', 'children': [], 'value': "'all'"},{'id': '115', 'type': 'string', 'children': [], 'value': "'cc'"},{'id': '116', 'type': 'string', 'children': [], 'value': "'gpl'"},{'id': '117', 'type': 'string', 'children': [], 'value': "'odb'"},{'id': '118', 'type': 'string', 'children': [], 'value': "'other'"},{'id': '119', 'type': 'if_statement', 'children': ['120', '125']},{'id': '120', 'type': 'boolean_operator', 'children': ['121', '122'], 'value': 'and'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'license_name'},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': 'not'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'license_name'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'valid_license_names'},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'raise_statement', 'children': ['127']},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'binary_operator', 'children': ['131', '132'], 'value': '+'},{'id': '131', 'type': 'string', 'children': [], 'value': "'Invalid license specified. Valid options are '"},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'valid_license_names'},{'id': '136', 'type': 'if_statement', 'children': ['137', '143']},{'id': '137', 'type': 'comparison_operator', 'children': ['138', '142'], 'value': '<='},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '142', 'type': 'integer', 'children': [], 'value': '0'},{'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': "'Page number must be >= 1'"},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '152', 'type': 'string', 'children': [], 'value': "'public'"},{'id': '153', 'type': 'if_statement', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'mine'},{'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': 'group'},{'id': '159', 'type': 'string', 'children': [], 'value': "'my'"},{'id': '160', 'type': 'if_statement', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'raise_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'string', 'children': [], 'value': "'Cannot specify both mine and a user'"},{'id': '168', 'type': 'if_statement', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'user'},{'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': 'group'},{'id': '174', 'type': 'string', 'children': [], 'value': "'user'"},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'datasets_list_result'},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'process_response'},{'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': 'self'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'datasets_list_with_http_info'},{'id': '187', 'type': 'argument_list', 'children': ['188', '191', '196', '201', '206', '211', '216', '221', '226']},{'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': 'sort_by'},{'id': '193', 'type': 'boolean_operator', 'children': ['194', '195'], 'value': 'or'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '195', 'type': 'string', 'children': [], 'value': "'hottest'"},{'id': '196', 'type': 'keyword_argument', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '198', 'type': 'boolean_operator', 'children': ['199', '200'], 'value': 'or'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '200', 'type': 'string', 'children': [], 'value': "'all'"},{'id': '201', 'type': 'keyword_argument', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'filetype'},{'id': '203', 'type': 'boolean_operator', 'children': ['204', '205'], 'value': 'or'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'file_type'},{'id': '205', 'type': 'string', 'children': [], 'value': "'all'"},{'id': '206', 'type': 'keyword_argument', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'license'},{'id': '208', 'type': 'boolean_operator', 'children': ['209', '210'], 'value': 'or'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'license_name'},{'id': '210', 'type': 'string', 'children': [], 'value': "'all'"},{'id': '211', 'type': 'keyword_argument', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'tagids'},{'id': '213', 'type': 'boolean_operator', 'children': ['214', '215'], 'value': 'or'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'tag_ids'},{'id': '215', 'type': 'string', 'children': [], 'value': "''"},{'id': '216', 'type': 'keyword_argument', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '218', 'type': 'boolean_operator', 'children': ['219', '220'], 'value': 'or'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '220', 'type': 'string', 'children': [], 'value': "''"},{'id': '221', 'type': 'keyword_argument', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '223', 'type': 'boolean_operator', 'children': ['224', '225'], 'value': 'or'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '225', 'type': 'string', 'children': [], 'value': "''"},{'id': '226', 'type': 'keyword_argument', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '229', 'type': 'return_statement', 'children': ['230']},{'id': '230', 'type': 'list_comprehension', 'children': ['231', '235']},{'id': '231', 'type': 'call', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'Dataset'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '235', 'type': 'for_in_clause', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'datasets_list_result'} | def dataset_list(self,
sort_by=None,
size=None,
file_type=None,
license_name=None,
tag_ids=None,
search=None,
user=None,
mine=False,
page=1):
valid_sort_bys = ['hottest', 'votes', 'updated', 'active', 'published']
if sort_by and sort_by not in valid_sort_bys:
raise ValueError('Invalid sort by specified. Valid options are ' +
str(valid_sort_bys))
valid_sizes = ['all', 'small', 'medium', 'large']
if size and size not in valid_sizes:
raise ValueError('Invalid size specified. Valid options are ' +
str(valid_sizes))
valid_file_types = ['all', 'csv', 'sqlite', 'json', 'bigQuery']
if file_type and file_type not in valid_file_types:
raise ValueError('Invalid file type specified. Valid options are '
+ str(valid_file_types))
valid_license_names = ['all', 'cc', 'gpl', 'odb', 'other']
if license_name and license_name not in valid_license_names:
raise ValueError('Invalid license specified. Valid options are ' +
str(valid_license_names))
if int(page) <= 0:
raise ValueError('Page number must be >= 1')
group = 'public'
if mine:
group = 'my'
if user:
raise ValueError('Cannot specify both mine and a user')
if user:
group = 'user'
datasets_list_result = self.process_response(
self.datasets_list_with_http_info(
group=group,
sort_by=sort_by or 'hottest',
size=size or 'all',
filetype=file_type or 'all',
license=license_name or 'all',
tagids=tag_ids or '',
search=search or '',
user=user or '',
page=page))
return [Dataset(d) for d in datasets_list_result] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '35']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'dataset_list_cli'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'file_type'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'license_name'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'tag_ids'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'mine'},{'id': '28', 'type': 'False', 'children': []},{'id': '29', 'type': 'default_parameter', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '31', 'type': 'integer', 'children': [], 'value': '1'},{'id': '32', 'type': 'default_parameter', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'csv_display'},{'id': '34', 'type': 'False', 'children': []},{'id': '35', 'type': 'block', 'children': ['36', '53', '62']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'datasets'},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'dataset_list'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45', '46', '47', '48', '49', '50', '51', '52']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'file_type'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'license_name'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'tag_ids'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'mine'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '56', 'type': 'list', 'children': ['57', '58', '59', '60', '61'], 'value': "['ref', 'title', 'size', 'lastUpdated', 'downloadCount']"},{'id': '57', 'type': 'string', 'children': [], 'value': "'ref'"},{'id': '58', 'type': 'string', 'children': [], 'value': "'title'"},{'id': '59', 'type': 'string', 'children': [], 'value': "'size'"},{'id': '60', 'type': 'string', 'children': [], 'value': "'lastUpdated'"},{'id': '61', 'type': 'string', 'children': [], 'value': "'downloadCount'"},{'id': '62', 'type': 'if_statement', 'children': ['63', '64', '86']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'datasets'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'if_statement', 'children': ['66', '67', '76']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'csv_display'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'print_csv'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'datasets'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '76', 'type': 'else_clause', 'children': ['77']},{'id': '77', 'type': 'block', 'children': ['78']},{'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': 'print_table'},{'id': '83', 'type': 'argument_list', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'datasets'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '86', 'type': 'else_clause', 'children': ['87']},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'string', 'children': [], 'value': "'No datasets found'"} | def dataset_list_cli(self,
sort_by=None,
size=None,
file_type=None,
license_name=None,
tag_ids=None,
search=None,
user=None,
mine=False,
page=1,
csv_display=False):
datasets = self.dataset_list(sort_by, size, file_type, license_name,
tag_ids, search, user, mine, page)
fields = ['ref', 'title', 'size', 'lastUpdated', 'downloadCount']
if datasets:
if csv_display:
self.print_csv(datasets, fields)
else:
self.print_table(datasets, fields)
else:
print('No datasets found') |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '41']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'kernels_list'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32', '35', '38']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '7', 'type': 'integer', 'children': [], 'value': '1'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '10', 'type': 'integer', 'children': [], 'value': '20'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'competition'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'parent_kernel'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'mine'},{'id': '25', 'type': 'False', 'children': []},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '28', 'type': 'None', 'children': []},{'id': '29', 'type': 'default_parameter', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'default_parameter', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'kernel_type'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'default_parameter', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'output_type'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'default_parameter', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '40', 'type': 'None', 'children': []},{'id': '41', 'type': 'block', 'children': ['42', '55', '62', '72', '81', '90', '107', '114', '131', '138', '155', '168', '185', '199', '206', '213', '217', '224', '291']},{'id': '42', 'type': 'if_statement', 'children': ['43', '49']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '48'], 'value': '<='},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '48', 'type': 'integer', 'children': [], 'value': '0'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'raise_statement', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'string', 'children': [], 'value': "'Page number must be >= 1'"},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '62', 'type': 'if_statement', 'children': ['63', '66']},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': '<='},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '65', 'type': 'integer', 'children': [], 'value': '0'},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'raise_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'string', 'children': [], 'value': "'Page size must be >= 1'"},{'id': '72', 'type': 'if_statement', 'children': ['73', '76']},{'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': '>'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '75', 'type': 'integer', 'children': [], 'value': '100'},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '80', 'type': 'integer', 'children': [], 'value': '100'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'valid_languages'},{'id': '84', 'type': 'list', 'children': ['85', '86', '87', '88', '89'], 'value': "['all', 'python', 'r', 'sqlite', 'julia']"},{'id': '85', 'type': 'string', 'children': [], 'value': "'all'"},{'id': '86', 'type': 'string', 'children': [], 'value': "'python'"},{'id': '87', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '88', 'type': 'string', 'children': [], 'value': "'sqlite'"},{'id': '89', 'type': 'string', 'children': [], 'value': "'julia'"},{'id': '90', 'type': 'if_statement', 'children': ['91', '96']},{'id': '91', 'type': 'boolean_operator', 'children': ['92', '93'], 'value': 'and'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': 'not'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'valid_languages'},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'raise_statement', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'binary_operator', 'children': ['102', '103'], 'value': '+'},{'id': '102', 'type': 'string', 'children': [], 'value': "'Invalid language specified. Valid options are '"},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'valid_languages'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'valid_kernel_types'},{'id': '110', 'type': 'list', 'children': ['111', '112', '113'], 'value': "['all', 'script', 'notebook']"},{'id': '111', 'type': 'string', 'children': [], 'value': "'all'"},{'id': '112', 'type': 'string', 'children': [], 'value': "'script'"},{'id': '113', 'type': 'string', 'children': [], 'value': "'notebook'"},{'id': '114', 'type': 'if_statement', 'children': ['115', '120']},{'id': '115', 'type': 'boolean_operator', 'children': ['116', '117'], 'value': 'and'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'kernel_type'},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '119'], 'value': 'not'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'kernel_type'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'valid_kernel_types'},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'raise_statement', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'binary_operator', 'children': ['126', '127'], 'value': '+'},{'id': '126', 'type': 'string', 'children': [], 'value': "'Invalid kernel type specified. Valid options are '"},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'valid_kernel_types'},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'valid_output_types'},{'id': '134', 'type': 'list', 'children': ['135', '136', '137'], 'value': "['all', 'visualization', 'data']"},{'id': '135', 'type': 'string', 'children': [], 'value': "'all'"},{'id': '136', 'type': 'string', 'children': [], 'value': "'visualization'"},{'id': '137', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '138', 'type': 'if_statement', 'children': ['139', '144']},{'id': '139', 'type': 'boolean_operator', 'children': ['140', '141'], 'value': 'and'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'output_type'},{'id': '141', 'type': 'comparison_operator', 'children': ['142', '143'], 'value': 'not'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'output_type'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'valid_output_types'},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'raise_statement', 'children': ['146']},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'binary_operator', 'children': ['150', '151'], 'value': '+'},{'id': '150', 'type': 'string', 'children': [], 'value': "'Invalid output type specified. Valid options are '"},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'valid_output_types'},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'valid_sort_by'},{'id': '158', 'type': 'list', 'children': ['159', '160', '161', '162', '163', '164', '165', '166', '167'], 'value': "[\n 'hotness', 'commentCount', 'dateCreated', 'dateRun', 'relevance',\n 'scoreAscending', 'scoreDescending', 'viewCount', 'voteCount'\n ]"},{'id': '159', 'type': 'string', 'children': [], 'value': "'hotness'"},{'id': '160', 'type': 'string', 'children': [], 'value': "'commentCount'"},{'id': '161', 'type': 'string', 'children': [], 'value': "'dateCreated'"},{'id': '162', 'type': 'string', 'children': [], 'value': "'dateRun'"},{'id': '163', 'type': 'string', 'children': [], 'value': "'relevance'"},{'id': '164', 'type': 'string', 'children': [], 'value': "'scoreAscending'"},{'id': '165', 'type': 'string', 'children': [], 'value': "'scoreDescending'"},{'id': '166', 'type': 'string', 'children': [], 'value': "'viewCount'"},{'id': '167', 'type': 'string', 'children': [], 'value': "'voteCount'"},{'id': '168', 'type': 'if_statement', 'children': ['169', '174']},{'id': '169', 'type': 'boolean_operator', 'children': ['170', '171'], 'value': 'and'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '171', 'type': 'comparison_operator', 'children': ['172', '173'], 'value': 'not'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'valid_sort_by'},{'id': '174', 'type': 'block', 'children': ['175']},{'id': '175', 'type': 'raise_statement', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'binary_operator', 'children': ['180', '181'], 'value': '+'},{'id': '180', 'type': 'string', 'children': [], 'value': "'Invalid sort by type specified. Valid options are '"},{'id': '181', 'type': 'call', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'valid_sort_by'},{'id': '185', 'type': 'if_statement', 'children': ['186', '193']},{'id': '186', 'type': 'boolean_operator', 'children': ['187', '190'], 'value': 'and'},{'id': '187', 'type': 'comparison_operator', 'children': ['188', '189'], 'value': '=='},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '189', 'type': 'string', 'children': [], 'value': "'relevance'"},{'id': '190', 'type': 'comparison_operator', 'children': ['191', '192'], 'value': '=='},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '192', 'type': 'string', 'children': [], 'value': "''"},{'id': '193', 'type': 'block', 'children': ['194']},{'id': '194', 'type': 'raise_statement', 'children': ['195']},{'id': '195', 'type': 'call', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'string', 'children': [], 'value': "'Cannot sort by relevance without a search term.'"},{'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': 'self'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'validate_dataset_string'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'call', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'validate_kernel_string'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'parent_kernel'},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'assignment', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '216', 'type': 'string', 'children': [], 'value': "'everyone'"},{'id': '217', 'type': 'if_statement', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'mine'},{'id': '219', 'type': 'block', 'children': ['220']},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'assignment', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '223', 'type': 'string', 'children': [], 'value': "'profile'"},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'kernels_list_result'},{'id': '227', 'type': 'call', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'process_response'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'call', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'kernels_list_with_http_info'},{'id': '236', 'type': 'argument_list', 'children': ['237', '240', '243', '246', '251', '256', '261', '266', '271', '276', '281', '286']},{'id': '237', 'type': 'keyword_argument', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '240', 'type': 'keyword_argument', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '243', 'type': 'keyword_argument', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '246', 'type': 'keyword_argument', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '248', 'type': 'boolean_operator', 'children': ['249', '250'], 'value': 'or'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '250', 'type': 'string', 'children': [], 'value': "''"},{'id': '251', 'type': 'keyword_argument', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '253', 'type': 'boolean_operator', 'children': ['254', '255'], 'value': 'or'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '255', 'type': 'string', 'children': [], 'value': "'all'"},{'id': '256', 'type': 'keyword_argument', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'kernel_type'},{'id': '258', 'type': 'boolean_operator', 'children': ['259', '260'], 'value': 'or'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'kernel_type'},{'id': '260', 'type': 'string', 'children': [], 'value': "'all'"},{'id': '261', 'type': 'keyword_argument', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'output_type'},{'id': '263', 'type': 'boolean_operator', 'children': ['264', '265'], 'value': 'or'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'output_type'},{'id': '265', 'type': 'string', 'children': [], 'value': "'all'"},{'id': '266', 'type': 'keyword_argument', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '268', 'type': 'boolean_operator', 'children': ['269', '270'], 'value': 'or'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '270', 'type': 'string', 'children': [], 'value': "'hotness'"},{'id': '271', 'type': 'keyword_argument', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '273', 'type': 'boolean_operator', 'children': ['274', '275'], 'value': 'or'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '275', 'type': 'string', 'children': [], 'value': "''"},{'id': '276', 'type': 'keyword_argument', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'competition'},{'id': '278', 'type': 'boolean_operator', 'children': ['279', '280'], 'value': 'or'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'competition'},{'id': '280', 'type': 'string', 'children': [], 'value': "''"},{'id': '281', 'type': 'keyword_argument', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'parent_kernel'},{'id': '283', 'type': 'boolean_operator', 'children': ['284', '285'], 'value': 'or'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'parent_kernel'},{'id': '285', 'type': 'string', 'children': [], 'value': "''"},{'id': '286', 'type': 'keyword_argument', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '288', 'type': 'boolean_operator', 'children': ['289', '290'], 'value': 'or'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '290', 'type': 'string', 'children': [], 'value': "''"},{'id': '291', 'type': 'return_statement', 'children': ['292']},{'id': '292', 'type': 'list_comprehension', 'children': ['293', '297']},{'id': '293', 'type': 'call', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'Kernel'},{'id': '295', 'type': 'argument_list', 'children': ['296']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '297', 'type': 'for_in_clause', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'kernels_list_result'} | def kernels_list(self,
page=1,
page_size=20,
dataset=None,
competition=None,
parent_kernel=None,
search=None,
mine=False,
user=None,
language=None,
kernel_type=None,
output_type=None,
sort_by=None):
if int(page) <= 0:
raise ValueError('Page number must be >= 1')
page_size = int(page_size)
if page_size <= 0:
raise ValueError('Page size must be >= 1')
if page_size > 100:
page_size = 100
valid_languages = ['all', 'python', 'r', 'sqlite', 'julia']
if language and language not in valid_languages:
raise ValueError('Invalid language specified. Valid options are ' +
str(valid_languages))
valid_kernel_types = ['all', 'script', 'notebook']
if kernel_type and kernel_type not in valid_kernel_types:
raise ValueError(
'Invalid kernel type specified. Valid options are ' +
str(valid_kernel_types))
valid_output_types = ['all', 'visualization', 'data']
if output_type and output_type not in valid_output_types:
raise ValueError(
'Invalid output type specified. Valid options are ' +
str(valid_output_types))
valid_sort_by = [
'hotness', 'commentCount', 'dateCreated', 'dateRun', 'relevance',
'scoreAscending', 'scoreDescending', 'viewCount', 'voteCount'
]
if sort_by and sort_by not in valid_sort_by:
raise ValueError(
'Invalid sort by type specified. Valid options are ' +
str(valid_sort_by))
if sort_by == 'relevance' and search == '':
raise ValueError('Cannot sort by relevance without a search term.')
self.validate_dataset_string(dataset)
self.validate_kernel_string(parent_kernel)
group = 'everyone'
if mine:
group = 'profile'
kernels_list_result = self.process_response(
self.kernels_list_with_http_info(
page=page,
page_size=page_size,
group=group,
user=user or '',
language=language or 'all',
kernel_type=kernel_type or 'all',
output_type=output_type or 'all',
sort_by=sort_by or 'hotness',
dataset=dataset or '',
competition=competition or '',
parent_kernel=parent_kernel or '',
search=search or ''))
return [Kernel(k) for k in kernels_list_result] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_salt_params'},{'id': '3', 'type': 'parameters', 'children': []},{'id': '4', 'type': 'block', 'children': ['5', '7', '15', '23', '27', '189']},{'id': '5', 'type': 'expression_statement', 'children': ['6']},{'id': '6', 'type': 'string', 'children': [], 'value': "'''\n Try to get all sort of parameters for Server Density server info.\n NOTE: Missing publicDNS and publicIPs parameters. There might be way of\n getting them with salt-cloud.\n '''"},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'all_stats'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'subscript', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': '__salt__'},{'id': '13', 'type': 'string', 'children': [], 'value': "'status.all_status'"},{'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': 'all_grains'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'subscript', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': '__salt__'},{'id': '21', 'type': 'string', 'children': [], 'value': "'grains.items'"},{'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': 'params'},{'id': '26', 'type': 'dictionary', 'children': []},{'id': '27', 'type': 'try_statement', 'children': ['28', '185']},{'id': '28', 'type': 'block', 'children': ['29', '37', '45', '82', '97', '107', '129', '151', '168']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '34']},{'id': '31', 'type': 'subscript', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '33', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '34', 'type': 'subscript', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'all_grains'},{'id': '36', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '42']},{'id': '39', 'type': 'subscript', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '41', 'type': 'string', 'children': [], 'value': "'hostname'"},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'all_grains'},{'id': '44', 'type': 'string', 'children': [], 'value': "'host'"},{'id': '45', 'type': 'if_statement', 'children': ['46', '51', '62']},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '50'], 'value': '=='},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'all_grains'},{'id': '49', 'type': 'string', 'children': [], 'value': "'kernel'"},{'id': '50', 'type': 'string', 'children': [], 'value': "'Darwin'"},{'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': 'sd_os'},{'id': '55', 'type': 'dictionary', 'children': ['56', '59']},{'id': '56', 'type': 'pair', 'children': ['57', '58']},{'id': '57', 'type': 'string', 'children': [], 'value': "'code'"},{'id': '58', 'type': 'string', 'children': [], 'value': "'mac'"},{'id': '59', 'type': 'pair', 'children': ['60', '61']},{'id': '60', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '61', 'type': 'string', 'children': [], 'value': "'Mac'"},{'id': '62', 'type': 'else_clause', 'children': ['63']},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'sd_os'},{'id': '67', 'type': 'dictionary', 'children': ['68', '77']},{'id': '68', 'type': 'pair', 'children': ['69', '70']},{'id': '69', 'type': 'string', 'children': [], 'value': "'code'"},{'id': '70', 'type': 'call', 'children': ['71', '76']},{'id': '71', 'type': 'attribute', 'children': ['72', '75']},{'id': '72', 'type': 'subscript', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'all_grains'},{'id': '74', 'type': 'string', 'children': [], 'value': "'kernel'"},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '76', 'type': 'argument_list', 'children': []},{'id': '77', 'type': 'pair', 'children': ['78', '79']},{'id': '78', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'all_grains'},{'id': '81', 'type': 'string', 'children': [], 'value': "'kernel'"},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '87']},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '86', 'type': 'string', 'children': [], 'value': "'os'"},{'id': '87', 'type': 'call', 'children': ['88', '95']},{'id': '88', 'type': 'attribute', 'children': ['89', '94']},{'id': '89', 'type': 'attribute', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'salt'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'sd_os'},{'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': 'params'},{'id': '101', 'type': 'string', 'children': [], 'value': "'cpuCores'"},{'id': '102', 'type': 'subscript', 'children': ['103', '106']},{'id': '103', 'type': 'subscript', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'all_stats'},{'id': '105', 'type': 'string', 'children': [], 'value': "'cpuinfo'"},{'id': '106', 'type': 'string', 'children': [], 'value': "'cpu cores'"},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '112']},{'id': '109', 'type': 'subscript', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '111', 'type': 'string', 'children': [], 'value': "'installedRAM'"},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'text_type'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'binary_operator', 'children': ['118', '128'], 'value': '/'},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'subscript', 'children': ['122', '127']},{'id': '122', 'type': 'subscript', 'children': ['123', '126']},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'all_stats'},{'id': '125', 'type': 'string', 'children': [], 'value': "'meminfo'"},{'id': '126', 'type': 'string', 'children': [], 'value': "'MemTotal'"},{'id': '127', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '128', 'type': 'integer', 'children': [], 'value': '1024'},{'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': 'params'},{'id': '133', 'type': 'string', 'children': [], 'value': "'swapSpace'"},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'text_type'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'binary_operator', 'children': ['140', '150'], 'value': '/'},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'subscript', 'children': ['144', '149']},{'id': '144', 'type': 'subscript', 'children': ['145', '148']},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'all_stats'},{'id': '147', 'type': 'string', 'children': [], 'value': "'meminfo'"},{'id': '148', 'type': 'string', 'children': [], 'value': "'SwapTotal'"},{'id': '149', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '150', 'type': 'integer', 'children': [], 'value': '1024'},{'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': 'params'},{'id': '155', 'type': 'string', 'children': [], 'value': "'privateIPs'"},{'id': '156', 'type': 'call', 'children': ['157', '164']},{'id': '157', 'type': 'attribute', 'children': ['158', '163']},{'id': '158', 'type': 'attribute', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'salt'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'subscript', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'all_grains'},{'id': '167', 'type': 'string', 'children': [], 'value': "'fqdn_ip4'"},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '173']},{'id': '170', 'type': 'subscript', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '172', 'type': 'string', 'children': [], 'value': "'privateDNS'"},{'id': '173', 'type': 'call', 'children': ['174', '181']},{'id': '174', 'type': 'attribute', 'children': ['175', '180']},{'id': '175', 'type': 'attribute', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'salt'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'subscript', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'all_grains'},{'id': '184', 'type': 'string', 'children': [], 'value': "'fqdn'"},{'id': '185', 'type': 'except_clause', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '187', 'type': 'block', 'children': ['188']},{'id': '188', 'type': 'pass_statement', 'children': []},{'id': '189', 'type': 'return_statement', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'params'} | def _get_salt_params():
'''
Try to get all sort of parameters for Server Density server info.
NOTE: Missing publicDNS and publicIPs parameters. There might be way of
getting them with salt-cloud.
'''
all_stats = __salt__['status.all_status']()
all_grains = __salt__['grains.items']()
params = {}
try:
params['name'] = all_grains['id']
params['hostname'] = all_grains['host']
if all_grains['kernel'] == 'Darwin':
sd_os = {'code': 'mac', 'name': 'Mac'}
else:
sd_os = {'code': all_grains['kernel'].lower(), 'name': all_grains['kernel']}
params['os'] = salt.utils.json.dumps(sd_os)
params['cpuCores'] = all_stats['cpuinfo']['cpu cores']
params['installedRAM'] = six.text_type(int(all_stats['meminfo']['MemTotal']['value']) / 1024)
params['swapSpace'] = six.text_type(int(all_stats['meminfo']['SwapTotal']['value']) / 1024)
params['privateIPs'] = salt.utils.json.dumps(all_grains['fqdn_ip4'])
params['privateDNS'] = salt.utils.json.dumps(all_grains['fqdn'])
except KeyError:
pass
return params |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'zcard'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '20', '30']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'string', 'children': [], 'value': "'''\n Get the length of a sorted set in Redis\n CLI Example:\n .. code-block:: bash\n salt '*' redis.zcard foo_sorted\n '''"},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'server'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': '_connect'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27', '28', '29']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '30', 'type': 'return_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'server'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'zcard'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'key'} | def zcard(key, host=None, port=None, db=None, password=None):
'''
Get the length of a sorted set in Redis
CLI Example:
.. code-block:: bash
salt '*' redis.zcard foo_sorted
'''
server = _connect(host, port, db, password)
return server.zcard(key) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'zrange'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'block', 'children': ['20', '22', '32']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'string', 'children': [], 'value': "'''\n Get a range of values from a sorted set in Redis by index\n CLI Example:\n .. code-block:: bash\n salt '*' redis.zrange foo_sorted 0 10\n '''"},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'server'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': '_connect'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29', '30', '31']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '32', 'type': 'return_statement', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'server'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'zrange'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39', '40']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'stop'} | def zrange(key, start, stop, host=None, port=None, db=None, password=None):
'''
Get a range of values from a sorted set in Redis by index
CLI Example:
.. code-block:: bash
salt '*' redis.zrange foo_sorted 0 10
'''
server = _connect(host, port, db, password)
return server.zrange(key, start, stop) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_list'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13', '16']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'list_type'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'search_term'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'block', 'children': ['20', '22', '35', '66', '101', '112', '144', '178', '191', '198', '209', '213', '238']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'string', 'children': [], 'value': "'''\n Returns a list of domains for the particular user as a list of objects\n offset by ``page`` length of ``page_size``\n list_type : ALL\n One of ``ALL``, ``EXPIRING``, ``EXPIRED``\n search_term\n Keyword to look for on the domain list\n page : 1\n Number of result page to return\n page_size : 20\n Number of domains to be listed per page (minimum: ``10``, maximum:\n ``100``)\n sort_by\n One of ``NAME``, ``NAME_DESC``, ``EXPIREDATE``, ``EXPIREDATE_DESC``,\n ``CREATEDATE``, or ``CREATEDATE_DESC``\n CLI Example:\n .. code-block:: bash\n salt 'my-minion' namecheap_domains.get_list\n '''"},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '25', 'type': 'call', 'children': ['26', '33']},{'id': '26', 'type': 'attribute', 'children': ['27', '32']},{'id': '27', 'type': 'attribute', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'salt'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'namecheap'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'get_opts'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'string', 'children': [], 'value': "'namecheap.domains.getList'"},{'id': '35', 'type': 'if_statement', 'children': ['36', '39']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'is'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'list_type'},{'id': '38', 'type': 'None', 'children': []},{'id': '39', 'type': 'block', 'children': ['40', '60']},{'id': '40', 'type': 'if_statement', 'children': ['41', '47']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'not'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'list_type'},{'id': '43', 'type': 'list', 'children': ['44', '45', '46'], 'value': "['ALL', 'EXPIRING', 'EXPIRED']"},{'id': '44', 'type': 'string', 'children': [], 'value': "'ALL'"},{'id': '45', 'type': 'string', 'children': [], 'value': "'EXPIRING'"},{'id': '46', 'type': 'string', 'children': [], 'value': "'EXPIRED'"},{'id': '47', 'type': 'block', 'children': ['48', '55']},{'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': 'log'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'string', 'children': [], 'value': "'Invalid option for list_type'"},{'id': '55', 'type': 'raise_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'string', 'children': [], 'value': "'Invalid option for list_type'"},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '65']},{'id': '62', 'type': 'subscript', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '64', 'type': 'string', 'children': [], 'value': "'ListType'"},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'list_type'},{'id': '66', 'type': 'if_statement', 'children': ['67', '70']},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': 'is'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'search_term'},{'id': '69', 'type': 'None', 'children': []},{'id': '70', 'type': 'block', 'children': ['71', '95']},{'id': '71', 'type': 'if_statement', 'children': ['72', '78']},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '77'], 'value': '>'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'search_term'},{'id': '77', 'type': 'integer', 'children': [], 'value': '70'},{'id': '78', 'type': 'block', 'children': ['79', '86']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'string', 'children': [], 'value': "'search_term trimmed to first 70 characters'"},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'search_term'},{'id': '89', 'type': 'subscript', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'search_term'},{'id': '91', 'type': 'slice', 'children': ['92', '93', '94']},{'id': '92', 'type': 'integer', 'children': [], 'value': '0'},{'id': '93', 'type': 'colon', 'children': []},{'id': '94', 'type': 'integer', 'children': [], 'value': '70'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '100']},{'id': '97', 'type': 'subscript', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '99', 'type': 'string', 'children': [], 'value': "'SearchTerm'"},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'search_term'},{'id': '101', 'type': 'if_statement', 'children': ['102', '105']},{'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': 'is'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '104', 'type': 'None', 'children': []},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '111']},{'id': '108', 'type': 'subscript', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '110', 'type': 'string', 'children': [], 'value': "'Page'"},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '112', 'type': 'if_statement', 'children': ['113', '116']},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': 'is'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '115', 'type': 'None', 'children': []},{'id': '116', 'type': 'block', 'children': ['117', '138']},{'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': 'page_size'},{'id': '121', 'type': 'integer', 'children': [], 'value': '100'},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': '<'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '124', 'type': 'integer', 'children': [], 'value': '10'},{'id': '125', 'type': 'block', 'children': ['126', '133']},{'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': 'log'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'string', 'children': [], 'value': "'Invalid option for page'"},{'id': '133', 'type': 'raise_statement', 'children': ['134']},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'string', 'children': [], 'value': "'Invalid option for page'"},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '143']},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '142', 'type': 'string', 'children': [], 'value': "'PageSize'"},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '144', 'type': 'if_statement', 'children': ['145', '148']},{'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': 'is'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '147', 'type': 'None', 'children': []},{'id': '148', 'type': 'block', 'children': ['149', '172']},{'id': '149', 'type': 'if_statement', 'children': ['150', '159']},{'id': '150', 'type': 'comparison_operator', 'children': ['151', '152'], 'value': 'not'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '152', 'type': 'list', 'children': ['153', '154', '155', '156', '157', '158'], 'value': "['NAME', 'NAME_DESC', 'EXPIREDATE', 'EXPIREDATE_DESC', 'CREATEDATE', 'CREATEDATE_DESC']"},{'id': '153', 'type': 'string', 'children': [], 'value': "'NAME'"},{'id': '154', 'type': 'string', 'children': [], 'value': "'NAME_DESC'"},{'id': '155', 'type': 'string', 'children': [], 'value': "'EXPIREDATE'"},{'id': '156', 'type': 'string', 'children': [], 'value': "'EXPIREDATE_DESC'"},{'id': '157', 'type': 'string', 'children': [], 'value': "'CREATEDATE'"},{'id': '158', 'type': 'string', 'children': [], 'value': "'CREATEDATE_DESC'"},{'id': '159', 'type': 'block', 'children': ['160', '167']},{'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': 'log'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'string', 'children': [], 'value': "'Invalid option for sort_by'"},{'id': '167', 'type': 'raise_statement', 'children': ['168']},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'string', 'children': [], 'value': "'Invalid option for sort_by'"},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '177']},{'id': '174', 'type': 'subscript', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '176', 'type': 'string', 'children': [], 'value': "'SortBy'"},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'response_xml'},{'id': '181', 'type': 'call', 'children': ['182', '189']},{'id': '182', 'type': 'attribute', 'children': ['183', '188']},{'id': '183', 'type': 'attribute', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'salt'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'namecheap'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'get_request'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '191', 'type': 'if_statement', 'children': ['192', '195']},{'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': 'is'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'response_xml'},{'id': '194', 'type': 'None', 'children': []},{'id': '195', 'type': 'block', 'children': ['196']},{'id': '196', 'type': 'return_statement', 'children': ['197']},{'id': '197', 'type': 'list', 'children': [], 'value': '[]'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'domainresult'},{'id': '201', 'type': 'subscript', 'children': ['202', '208']},{'id': '202', 'type': 'call', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'response_xml'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'getElementsByTagName'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'string', 'children': [], 'value': '"DomainGetListResult"'},{'id': '208', 'type': 'integer', 'children': [], 'value': '0'},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'assignment', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'domains'},{'id': '212', 'type': 'list', 'children': [], 'value': '[]'},{'id': '213', 'type': 'for_statement', 'children': ['214', '215', '221']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '215', 'type': 'call', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'domainresult'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'getElementsByTagName'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'string', 'children': [], 'value': '"Domain"'},{'id': '221', 'type': 'block', 'children': ['222']},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'call', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'domains'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'call', 'children': ['229', '236']},{'id': '229', 'type': 'attribute', 'children': ['230', '235']},{'id': '230', 'type': 'attribute', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'salt'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'namecheap'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'atts_to_dict'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '238', 'type': 'return_statement', 'children': ['239']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'domains'} | def get_list(list_type=None,
search_term=None,
page=None,
page_size=None,
sort_by=None):
'''
Returns a list of domains for the particular user as a list of objects
offset by ``page`` length of ``page_size``
list_type : ALL
One of ``ALL``, ``EXPIRING``, ``EXPIRED``
search_term
Keyword to look for on the domain list
page : 1
Number of result page to return
page_size : 20
Number of domains to be listed per page (minimum: ``10``, maximum:
``100``)
sort_by
One of ``NAME``, ``NAME_DESC``, ``EXPIREDATE``, ``EXPIREDATE_DESC``,
``CREATEDATE``, or ``CREATEDATE_DESC``
CLI Example:
.. code-block:: bash
salt 'my-minion' namecheap_domains.get_list
'''
opts = salt.utils.namecheap.get_opts('namecheap.domains.getList')
if list_type is not None:
if list_type not in ['ALL', 'EXPIRING', 'EXPIRED']:
log.error('Invalid option for list_type')
raise Exception('Invalid option for list_type')
opts['ListType'] = list_type
if search_term is not None:
if len(search_term) > 70:
log.warning('search_term trimmed to first 70 characters')
search_term = search_term[0:70]
opts['SearchTerm'] = search_term
if page is not None:
opts['Page'] = page
if page_size is not None:
if page_size > 100 or page_size < 10:
log.error('Invalid option for page')
raise Exception('Invalid option for page')
opts['PageSize'] = page_size
if sort_by is not None:
if sort_by not in ['NAME', 'NAME_DESC', 'EXPIREDATE', 'EXPIREDATE_DESC', 'CREATEDATE', 'CREATEDATE_DESC']:
log.error('Invalid option for sort_by')
raise Exception('Invalid option for sort_by')
opts['SortBy'] = sort_by
response_xml = salt.utils.namecheap.get_request(opts)
if response_xml is None:
return []
domainresult = response_xml.getElementsByTagName("DomainGetListResult")[0]
domains = []
for d in domainresult.getElementsByTagName("Domain"):
domains.append(salt.utils.namecheap.atts_to_dict(d))
return domains |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort_policy'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '5', 'type': 'block', 'children': ['6', '8', '57']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''\n List-type sub-items in policies don't happen to be order-sensitive, but\n compare operations will render them unequal, leading to non-idempotent\n state runs. We'll sort any list-type subitems before comparison to reduce\n the likelihood of false negatives.\n '''"},{'id': '8', 'type': 'if_statement', 'children': ['9', '14', '27']},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '11', 'type': 'argument_list', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'return_statement', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'list_comprehension', 'children': ['20', '24']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': '_sort_policy'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '24', 'type': 'for_in_clause', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '27', 'type': 'elif_clause', 'children': ['28', '35']},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '32', 'type': 'tuple', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'return_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'list_comprehension', 'children': ['41', '47']},{'id': '41', 'type': 'tuple', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': '_sort_policy'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'v'},{'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', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '57', 'type': 'return_statement', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'doc'} | def _sort_policy(doc):
'''
List-type sub-items in policies don't happen to be order-sensitive, but
compare operations will render them unequal, leading to non-idempotent
state runs. We'll sort any list-type subitems before comparison to reduce
the likelihood of false negatives.
'''
if isinstance(doc, list):
return sorted([_sort_policy(i) for i in doc])
elif isinstance(doc, (dict, OrderedDict)):
return dict([(k, _sort_policy(v)) for k, v in six.iteritems(doc)])
return doc |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_resolve_datacenter'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'dc'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'pillarenv'},{'id': '6', 'type': 'block', 'children': ['7', '9', '17', '40', '51', '59', '82', '133']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'string', 'children': [], 'value': "'''\n If ``dc`` is a string - return it as is.\n If it's a dict then sort it in descending order by key length and try\n to use keys as RegEx patterns to match against ``pillarenv``.\n The value for matched pattern should be a string (that can use\n ``str.format`` syntax togetehr with captured variables from pattern)\n pointing to targe data center to use.\n If none patterns matched return ``None`` which meanse us datacenter of\n conencted Consul agent.\n '''"},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '14', 'type': 'argument_list', 'children': ['15', '16']},{'id': '15', 'type': 'string', 'children': [], 'value': "'Resolving Consul datacenter based on: %s'"},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'dc'},{'id': '17', 'type': 'try_statement', 'children': ['18', '27']},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'mappings'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'dc'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'except_clause', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '29', 'type': 'block', 'children': ['30', '38']},{'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': 'log'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'string', 'children': [], 'value': "'Using pre-defined DC: \\'%s\\''"},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'dc'},{'id': '38', 'type': 'return_statement', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'dc'},{'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': 'log'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47']},{'id': '46', 'type': 'string', 'children': [], 'value': "'Selecting DC based on pillarenv using %d pattern(s)'"},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'mappings'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58']},{'id': '57', 'type': 'string', 'children': [], 'value': "'Pillarenv set to \\'%s\\''"},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'pillarenv'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'sorted_mappings'},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '64', 'type': 'argument_list', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'mappings'},{'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '68', 'type': 'lambda', 'children': ['69', '71']},{'id': '69', 'type': 'lambda_parameters', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '71', 'type': 'tuple', 'children': ['72', '79']},{'id': '72', 'type': 'unary_operator', 'children': ['73'], 'value': '-'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '78', 'type': 'integer', 'children': [], 'value': '0'},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '81', 'type': 'integer', 'children': [], 'value': '0'},{'id': '82', 'type': 'for_statement', 'children': ['83', '86', '87']},{'id': '83', 'type': 'pattern_list', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'sorted_mappings'},{'id': '87', 'type': 'block', 'children': ['88', '98']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '95', 'type': 'argument_list', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'pillarenv'},{'id': '98', 'type': 'if_statement', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '100', 'type': 'block', 'children': ['101', '109', '123', '131']},{'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': 'log'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '106', 'type': 'argument_list', 'children': ['107', '108']},{'id': '107', 'type': 'string', 'children': [], 'value': "'Matched pattern: \\'%s\\''"},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'dictionary_splat', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'groupdict'},{'id': '122', 'type': 'argument_list', 'children': []},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '128', 'type': 'argument_list', 'children': ['129', '130']},{'id': '129', 'type': 'string', 'children': [], 'value': "'Resolved datacenter: \\'%s\\''"},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '131', 'type': 'return_statement', 'children': ['132']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'result'},{'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': 'log'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '138', 'type': 'argument_list', 'children': ['139', '140', '141']},{'id': '139', 'type': 'string', 'children': [], 'value': "'None of following patterns matched pillarenv=%s: %s'"},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'pillarenv'},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'string', 'children': [], 'value': "', '"},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '145', 'type': 'generator_expression', 'children': ['146', '150']},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'repr'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '150', 'type': 'for_in_clause', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'mappings'} | def _resolve_datacenter(dc, pillarenv):
'''
If ``dc`` is a string - return it as is.
If it's a dict then sort it in descending order by key length and try
to use keys as RegEx patterns to match against ``pillarenv``.
The value for matched pattern should be a string (that can use
``str.format`` syntax togetehr with captured variables from pattern)
pointing to targe data center to use.
If none patterns matched return ``None`` which meanse us datacenter of
conencted Consul agent.
'''
log.debug('Resolving Consul datacenter based on: %s', dc)
try:
mappings = dc.items()
except AttributeError:
log.debug('Using pre-defined DC: \'%s\'', dc)
return dc
log.debug('Selecting DC based on pillarenv using %d pattern(s)', len(mappings))
log.debug('Pillarenv set to \'%s\'', pillarenv)
sorted_mappings = sorted(mappings, key=lambda m: (-len(m[0]), m[0]))
for pattern, target in sorted_mappings:
match = re.match(pattern, pillarenv)
if match:
log.debug('Matched pattern: \'%s\'', pattern)
result = target.format(**match.groupdict())
log.debug('Resolved datacenter: \'%s\'', result)
return result
log.debug(
'None of following patterns matched pillarenv=%s: %s',
pillarenv, ', '.join(repr(x) for x in mappings)
) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'ERROR', 'children': ['2', '169', '176']},{'id': '2', 'type': 'function_definition', 'children': ['3', '4', '9']},{'id': '3', 'type': 'function_name', 'children': [], 'value': 'read_conf'},{'id': '4', 'type': 'parameters', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'conf_file'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'out_format'},{'id': '8', 'type': 'string', 'children': [], 'value': "'simple'"},{'id': '9', 'type': 'block', 'children': ['10', '12', '16', '20']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'string', 'children': [], 'value': "'''\n Read in an LXC configuration file. By default returns a simple, unsorted\n dict, but can also return a more detailed structure including blank lines\n and comments.\n out_format:\n set to 'simple' if you need the old and unsupported behavior.\n This won't support the multiple lxc values (eg: multiple network nics)\n CLI Examples:\n .. code-block:: bash\n salt 'minion' lxc.read_conf /etc/lxc/mycontainer.conf\n salt 'minion' lxc.read_conf /etc/lxc/mycontainer.conf out_format=commented\n '''"},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ret_commented'},{'id': '15', 'type': 'list', 'children': [], 'value': '[]'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'ret_simple'},{'id': '19', 'type': 'dictionary', 'children': []},{'id': '20', 'type': 'with_statement', 'children': ['21', '37']},{'id': '21', 'type': 'with_clause', 'children': ['22']},{'id': '22', 'type': 'with_item', 'children': ['23']},{'id': '23', 'type': 'as_pattern', 'children': ['24', '35']},{'id': '24', 'type': 'call', 'children': ['25', '32']},{'id': '25', 'type': 'attribute', 'children': ['26', '31']},{'id': '26', 'type': 'attribute', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'salt'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'fopen'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'conf_file'},{'id': '34', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '35', 'type': 'as_pattern_target', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'fp_'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'for_statement', 'children': ['39', '40', '54', '140']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '40', 'type': 'call', 'children': ['41', '48']},{'id': '41', 'type': 'attribute', 'children': ['42', '47']},{'id': '42', 'type': 'attribute', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'salt'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'fp_'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'readlines'},{'id': '53', 'type': 'argument_list', 'children': []},{'id': '54', 'type': 'ERROR', 'children': ['55', '68', '77', '94', '98', '105', '107', '139']},{'id': '55', 'type': 'if_statement', 'children': ['56', '59']},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'not'},{'id': '57', 'type': 'string', 'children': [], 'value': "'='"},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '59', 'type': 'block', 'children': ['60', '67']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'ret_commented'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '67', 'type': 'continue_statement', 'children': []},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'comps'},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'split'},{'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': 'value'},{'id': '80', 'type': 'call', 'children': ['81', '93']},{'id': '81', 'type': 'attribute', 'children': ['82', '92']},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'string', 'children': [], 'value': "'='"},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'comps'},{'id': '89', 'type': 'slice', 'children': ['90', '91']},{'id': '90', 'type': 'integer', 'children': [], 'value': '1'},{'id': '91', 'type': 'colon', 'children': []},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '93', 'type': 'argument_list', 'children': []},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'comment'},{'id': '97', 'type': 'None', 'children': []},{'id': '98', 'type': 'attribute', 'children': ['99', '104']},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '103', 'type': 'argument_list', 'children': []},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '105', 'type': 'ERROR', 'children': ['106']},{'id': '106', 'type': 'string', 'children': [], 'value': "'\n vcomps = value.strip().split('"},{'id': '107', 'type': 'keyword_argument', 'children': ['108', '109', '118']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '109', 'type': 'ERROR', 'children': ['110', '117']},{'id': '110', 'type': 'call', 'children': ['111', '116']},{'id': '111', 'type': 'attribute', 'children': ['112', '115']},{'id': '112', 'type': 'subscript', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'vcomps'},{'id': '114', 'type': 'integer', 'children': [], 'value': '1'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '116', 'type': 'argument_list', 'children': []},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'comment'},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'ret_commented'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'dictionary', 'children': ['124']},{'id': '124', 'type': 'pair', 'children': ['125', '132']},{'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': 'comps'},{'id': '129', 'type': 'integer', 'children': [], 'value': '0'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '131', 'type': 'argument_list', 'children': []},{'id': '132', 'type': 'dictionary', 'children': ['133', '136']},{'id': '133', 'type': 'pair', 'children': ['134', '135']},{'id': '134', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '136', 'type': 'pair', 'children': ['137', '138']},{'id': '137', 'type': 'string', 'children': [], 'value': "'comment'"},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'comment'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'else'},{'id': '140', 'type': 'block', 'children': ['141', '157']},{'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_commented'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'dictionary', 'children': ['148']},{'id': '148', 'type': 'pair', 'children': ['149', '156']},{'id': '149', 'type': 'call', 'children': ['150', '155']},{'id': '150', 'type': 'attribute', 'children': ['151', '154']},{'id': '151', 'type': 'subscript', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'comps'},{'id': '153', 'type': 'integer', 'children': [], 'value': '0'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '155', 'type': 'argument_list', 'children': []},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '168']},{'id': '159', 'type': 'subscript', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'ret_simple'},{'id': '161', 'type': 'call', 'children': ['162', '167']},{'id': '162', 'type': 'attribute', 'children': ['163', '166']},{'id': '163', 'type': 'subscript', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'comps'},{'id': '165', 'type': 'integer', 'children': [], 'value': '0'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '167', 'type': 'argument_list', 'children': []},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '169', 'type': 'if_statement', 'children': ['170', '173']},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '172'], 'value': '=='},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'out_format'},{'id': '172', 'type': 'string', 'children': [], 'value': "'simple'"},{'id': '173', 'type': 'block', 'children': ['174']},{'id': '174', 'type': 'return_statement', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'ret_simple'},{'id': '176', 'type': 'return_statement', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'ret_commented'} | def read_conf(conf_file, out_format='simple'):
'''
Read in an LXC configuration file. By default returns a simple, unsorted
dict, but can also return a more detailed structure including blank lines
and comments.
out_format:
set to 'simple' if you need the old and unsupported behavior.
This won't support the multiple lxc values (eg: multiple network nics)
CLI Examples:
.. code-block:: bash
salt 'minion' lxc.read_conf /etc/lxc/mycontainer.conf
salt 'minion' lxc.read_conf /etc/lxc/mycontainer.conf out_format=commented
'''
ret_commented = []
ret_simple = {}
with salt.utils.files.fopen(conf_file, 'r') as fp_:
for line in salt.utils.data.decode(fp_.readlines()):
if '=' not in line:
ret_commented.append(line)
continue
comps = line.split('=')
value = '='.join(comps[1:]).strip()
comment = None
if value.strip().startswith('
vcomps = value.strip().split('
value = vcomps[1].strip()
comment = '
ret_commented.append({comps[0].strip(): {
'value': value,
'comment': comment,
}})
else:
ret_commented.append({comps[0].strip(): value})
ret_simple[comps[0].strip()] = value
if out_format == 'simple':
return ret_simple
return ret_commented |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_top_targets'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'top'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'orders'},{'id': '7', 'type': 'block', 'children': ['8', '10', '19', '61']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'string', 'children': [], 'value': "'''\n Returns the sorted high data from the merged top files\n '''"},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sorted_top'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '19', 'type': 'for_statement', 'children': ['20', '23', '29']},{'id': '20', 'type': 'pattern_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'saltenv'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'targets'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'top'},{'id': '29', 'type': 'block', 'children': ['30', '47']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'sorted_targets'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'targets'},{'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '39', 'type': 'lambda', 'children': ['40', '42']},{'id': '40', 'type': 'lambda_parameters', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '42', 'type': 'subscript', 'children': ['43', '46']},{'id': '43', 'type': 'subscript', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'orders'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'saltenv'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '47', 'type': 'for_statement', 'children': ['48', '49', '50']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'sorted_targets'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '58']},{'id': '53', 'type': 'subscript', 'children': ['54', '57']},{'id': '54', 'type': 'subscript', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'sorted_top'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'saltenv'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'targets'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '61', 'type': 'return_statement', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'sorted_top'} | def sort_top_targets(self, top, orders):
'''
Returns the sorted high data from the merged top files
'''
sorted_top = collections.defaultdict(OrderedDict)
for saltenv, targets in six.iteritems(top):
sorted_targets = sorted(targets,
key=lambda target: orders[saltenv][target])
for target in sorted_targets:
sorted_top[saltenv][target] = targets[target]
return sorted_top |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '47']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'subvolume_list'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32', '35', '38', '41', '44']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'absolute'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'ogeneration'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'generation'},{'id': '16', 'type': 'False', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'subvolumes'},{'id': '19', 'type': 'False', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '22', 'type': 'False', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'parent_uuid'},{'id': '25', 'type': 'False', 'children': []},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'sent_subvolume_uuid'},{'id': '28', 'type': 'False', 'children': []},{'id': '29', 'type': 'default_parameter', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'snapshots'},{'id': '31', 'type': 'False', 'children': []},{'id': '32', 'type': 'default_parameter', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'readonly'},{'id': '34', 'type': 'False', 'children': []},{'id': '35', 'type': 'default_parameter', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'deleted'},{'id': '37', 'type': 'False', 'children': []},{'id': '38', 'type': 'default_parameter', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'generation_cmp'},{'id': '40', 'type': 'None', 'children': []},{'id': '41', 'type': 'default_parameter', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'ogeneration_cmp'},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': 'default_parameter', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '46', 'type': 'None', 'children': []},{'id': '47', 'type': 'block', 'children': ['48', '50', '65', '95', '114', '121', '158', '174', '186', '198', '218', '225', '234', '245', '259', '263', '318']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'string', 'children': [], 'value': "'''\n List the subvolumes present in the filesystem.\n path\n Mount point for the subvolume\n parent_id\n Print parent ID\n absolute\n Print all the subvolumes in the filesystem and distinguish\n between absolute and relative path with respect to the given\n <path>\n ogeneration\n Print the ogeneration of the subvolume\n generation\n Print the generation of the subvolume\n subvolumes\n Print only subvolumes below specified <path>\n uuid\n Print the UUID of the subvolume\n parent_uuid\n Print the parent uuid of subvolumes (and snapshots)\n sent_subvolume_uuid\n Print the UUID of the sent subvolume, where the subvolume is\n the result of a receive operation\n snapshots\n Only snapshot subvolumes in the filesystem will be listed\n readonly\n Only readonly subvolumes in the filesystem will be listed\n deleted\n Only deleted subvolumens that are ye not cleaned\n generation_cmp\n List subvolumes in the filesystem that its generation is >=,\n <= or = value. '+' means >= value, '-' means <= value, If\n there is neither '+' nor '-', it means = value\n ogeneration_cmp\n List subvolumes in the filesystem that its ogeneration is >=,\n <= or = value\n sort\n List subvolumes in order by specified items. Possible values:\n * rootid\n * gen\n * ogen\n * path\n You can add '+' or '-' in front of each items, '+' means\n ascending, '-' means descending. The default is ascending. You\n can combite it in a list.\n CLI Example:\n .. code-block:: bash\n salt '*' btrfs.subvolume_list /var/volumes/tmp\n salt '*' btrfs.subvolume_list /var/volumes/tmp path=True\n salt '*' btrfs.subvolume_list /var/volumes/tmp sort='[-rootid]'\n '''"},{'id': '50', 'type': 'if_statement', 'children': ['51', '59']},{'id': '51', 'type': 'boolean_operator', 'children': ['52', '53'], 'value': 'and'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '58'], 'value': 'is'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'raise_statement', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'CommandExecutionError'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'string', 'children': [], 'value': "'Sort parameter must be a list'"},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'valid_sorts'},{'id': '68', 'type': 'list_comprehension', 'children': ['69', '77']},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'string', 'children': [], 'value': "''"},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'tuple', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '77', 'type': 'for_in_clause', 'children': ['78', '81']},{'id': '78', 'type': 'pattern_list', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'product'},{'id': '85', 'type': 'argument_list', 'children': ['86', '90']},{'id': '86', 'type': 'tuple', 'children': ['87', '88', '89']},{'id': '87', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '88', 'type': 'string', 'children': [], 'value': "''"},{'id': '89', 'type': 'string', 'children': [], 'value': "'+'"},{'id': '90', 'type': 'tuple', 'children': ['91', '92', '93', '94']},{'id': '91', 'type': 'string', 'children': [], 'value': "'rootid'"},{'id': '92', 'type': 'string', 'children': [], 'value': "'gen'"},{'id': '93', 'type': 'string', 'children': [], 'value': "'ogen'"},{'id': '94', 'type': 'string', 'children': [], 'value': "'path'"},{'id': '95', 'type': 'if_statement', 'children': ['96', '108']},{'id': '96', 'type': 'boolean_operator', 'children': ['97', '98'], 'value': 'and'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '98', 'type': 'not_operator', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '101', 'type': 'generator_expression', 'children': ['102', '105']},{'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': 'in'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'valid_sorts'},{'id': '105', 'type': 'for_in_clause', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'raise_statement', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'CommandExecutionError'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'string', 'children': [], 'value': "'Value for sort not recognized'"},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '117', 'type': 'list', 'children': ['118', '119', '120'], 'value': "['btrfs', 'subvolume', 'list']"},{'id': '118', 'type': 'string', 'children': [], 'value': "'btrfs'"},{'id': '119', 'type': 'string', 'children': [], 'value': "'subvolume'"},{'id': '120', 'type': 'string', 'children': [], 'value': "'list'"},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '124', 'type': 'tuple', 'children': ['125', '128', '131', '134', '137', '140', '143', '146', '149', '152', '155']},{'id': '125', 'type': 'tuple', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '127', 'type': 'string', 'children': [], 'value': "'-p'"},{'id': '128', 'type': 'tuple', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'absolute'},{'id': '130', 'type': 'string', 'children': [], 'value': "'-a'"},{'id': '131', 'type': 'tuple', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'ogeneration'},{'id': '133', 'type': 'string', 'children': [], 'value': "'-c'"},{'id': '134', 'type': 'tuple', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'generation'},{'id': '136', 'type': 'string', 'children': [], 'value': "'-g'"},{'id': '137', 'type': 'tuple', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'subvolumes'},{'id': '139', 'type': 'string', 'children': [], 'value': "'-o'"},{'id': '140', 'type': 'tuple', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '142', 'type': 'string', 'children': [], 'value': "'-u'"},{'id': '143', 'type': 'tuple', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'parent_uuid'},{'id': '145', 'type': 'string', 'children': [], 'value': "'-q'"},{'id': '146', 'type': 'tuple', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'sent_subvolume_uuid'},{'id': '148', 'type': 'string', 'children': [], 'value': "'-R'"},{'id': '149', 'type': 'tuple', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'snapshots'},{'id': '151', 'type': 'string', 'children': [], 'value': "'-s'"},{'id': '152', 'type': 'tuple', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'readonly'},{'id': '154', 'type': 'string', 'children': [], 'value': "'-r'"},{'id': '155', 'type': 'tuple', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'deleted'},{'id': '157', 'type': 'string', 'children': [], 'value': "'-d'"},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '163', 'type': 'generator_expression', 'children': ['164', '167', '170']},{'id': '164', 'type': 'subscript', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '166', 'type': 'integer', 'children': [], 'value': '1'},{'id': '167', 'type': 'for_in_clause', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '170', 'type': 'if_clause', 'children': ['171']},{'id': '171', 'type': 'subscript', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '173', 'type': 'integer', 'children': [], 'value': '0'},{'id': '174', 'type': 'if_statement', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'generation_cmp'},{'id': '176', 'type': 'block', 'children': ['177']},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'list', 'children': ['184', '185'], 'value': "['-G', generation_cmp]"},{'id': '184', 'type': 'string', 'children': [], 'value': "'-G'"},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'generation_cmp'},{'id': '186', 'type': 'if_statement', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'ogeneration_cmp'},{'id': '188', 'type': 'block', 'children': ['189']},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'call', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'list', 'children': ['196', '197'], 'value': "['-C', ogeneration_cmp]"},{'id': '196', 'type': 'string', 'children': [], 'value': "'-C'"},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'ogeneration_cmp'},{'id': '198', 'type': 'if_statement', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '200', 'type': 'block', 'children': ['201']},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'call', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'call', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'string', 'children': [], 'value': "'--sort={}'"},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'call', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'string', 'children': [], 'value': "','"},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'sort'},{'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': 'cmd'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '228', 'type': 'call', 'children': ['229', '232']},{'id': '229', 'type': 'subscript', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': '__salt__'},{'id': '231', 'type': 'string', 'children': [], 'value': "'cmd.run_all'"},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'call', 'children': ['236', '243']},{'id': '236', 'type': 'attribute', 'children': ['237', '242']},{'id': '237', 'type': 'attribute', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'salt'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'fsutils'},{'id': '242', 'type': 'identifier', 'children': [], 'value': '_verify_run'},{'id': '243', 'type': 'argument_list', 'children': ['244']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'assignment', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '248', 'type': 'tuple', 'children': ['249', '250', '251', '252', '253', '254', '255', '256', '257', '258']},{'id': '249', 'type': 'string', 'children': [], 'value': "'ID'"},{'id': '250', 'type': 'string', 'children': [], 'value': "'gen'"},{'id': '251', 'type': 'string', 'children': [], 'value': "'cgen'"},{'id': '252', 'type': 'string', 'children': [], 'value': "'parent'"},{'id': '253', 'type': 'string', 'children': [], 'value': "'top level'"},{'id': '254', 'type': 'string', 'children': [], 'value': "'otime'"},{'id': '255', 'type': 'string', 'children': [], 'value': "'parent_uuid'"},{'id': '256', 'type': 'string', 'children': [], 'value': "'received_uuid'"},{'id': '257', 'type': 'string', 'children': [], 'value': "'uuid'"},{'id': '258', 'type': 'string', 'children': [], 'value': "'path'"},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'assignment', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '262', 'type': 'list', 'children': [], 'value': '[]'},{'id': '263', 'type': 'for_statement', 'children': ['264', '265', '272']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '265', 'type': 'call', 'children': ['266', '271']},{'id': '266', 'type': 'attribute', 'children': ['267', '270']},{'id': '267', 'type': 'subscript', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '269', 'type': 'string', 'children': [], 'value': "'stdout'"},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'splitlines'},{'id': '271', 'type': 'argument_list', 'children': []},{'id': '272', 'type': 'block', 'children': ['273', '277', '307']},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'assignment', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '276', 'type': 'dictionary', 'children': []},{'id': '277', 'type': 'for_statement', 'children': ['278', '279', '280']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '280', 'type': 'block', 'children': ['281', '294']},{'id': '281', 'type': 'expression_statement', 'children': ['282']},{'id': '282', 'type': 'assignment', 'children': ['283', '286']},{'id': '283', 'type': 'pattern_list', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '286', 'type': 'call', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': '_pop'},{'id': '288', 'type': 'argument_list', 'children': ['289', '290', '291']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '291', 'type': 'comparison_operator', 'children': ['292', '293'], 'value': '=='},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '293', 'type': 'string', 'children': [], 'value': "'path'"},{'id': '294', 'type': 'if_statement', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '296', 'type': 'block', 'children': ['297']},{'id': '297', 'type': 'expression_statement', 'children': ['298']},{'id': '298', 'type': 'assignment', 'children': ['299', '306']},{'id': '299', 'type': 'subscript', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '301', 'type': 'call', 'children': ['302', '305']},{'id': '302', 'type': 'attribute', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '305', 'type': 'argument_list', 'children': []},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '307', 'type': 'if_statement', 'children': ['308', '310']},{'id': '308', 'type': 'not_operator', 'children': ['309']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '310', 'type': 'block', 'children': ['311']},{'id': '311', 'type': 'expression_statement', 'children': ['312']},{'id': '312', 'type': 'call', 'children': ['313', '316']},{'id': '313', 'type': 'attribute', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '316', 'type': 'argument_list', 'children': ['317']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '318', 'type': 'return_statement', 'children': ['319']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'result'} | def subvolume_list(path, parent_id=False, absolute=False,
ogeneration=False, generation=False,
subvolumes=False, uuid=False, parent_uuid=False,
sent_subvolume_uuid=False, snapshots=False,
readonly=False, deleted=False, generation_cmp=None,
ogeneration_cmp=None, sort=None):
'''
List the subvolumes present in the filesystem.
path
Mount point for the subvolume
parent_id
Print parent ID
absolute
Print all the subvolumes in the filesystem and distinguish
between absolute and relative path with respect to the given
<path>
ogeneration
Print the ogeneration of the subvolume
generation
Print the generation of the subvolume
subvolumes
Print only subvolumes below specified <path>
uuid
Print the UUID of the subvolume
parent_uuid
Print the parent uuid of subvolumes (and snapshots)
sent_subvolume_uuid
Print the UUID of the sent subvolume, where the subvolume is
the result of a receive operation
snapshots
Only snapshot subvolumes in the filesystem will be listed
readonly
Only readonly subvolumes in the filesystem will be listed
deleted
Only deleted subvolumens that are ye not cleaned
generation_cmp
List subvolumes in the filesystem that its generation is >=,
<= or = value. '+' means >= value, '-' means <= value, If
there is neither '+' nor '-', it means = value
ogeneration_cmp
List subvolumes in the filesystem that its ogeneration is >=,
<= or = value
sort
List subvolumes in order by specified items. Possible values:
* rootid
* gen
* ogen
* path
You can add '+' or '-' in front of each items, '+' means
ascending, '-' means descending. The default is ascending. You
can combite it in a list.
CLI Example:
.. code-block:: bash
salt '*' btrfs.subvolume_list /var/volumes/tmp
salt '*' btrfs.subvolume_list /var/volumes/tmp path=True
salt '*' btrfs.subvolume_list /var/volumes/tmp sort='[-rootid]'
'''
if sort and type(sort) is not list:
raise CommandExecutionError('Sort parameter must be a list')
valid_sorts = [
''.join((order, attrib)) for order, attrib in itertools.product(
('-', '', '+'), ('rootid', 'gen', 'ogen', 'path'))
]
if sort and not all(s in valid_sorts for s in sort):
raise CommandExecutionError('Value for sort not recognized')
cmd = ['btrfs', 'subvolume', 'list']
params = ((parent_id, '-p'),
(absolute, '-a'),
(ogeneration, '-c'),
(generation, '-g'),
(subvolumes, '-o'),
(uuid, '-u'),
(parent_uuid, '-q'),
(sent_subvolume_uuid, '-R'),
(snapshots, '-s'),
(readonly, '-r'),
(deleted, '-d'))
cmd.extend(p[1] for p in params if p[0])
if generation_cmp:
cmd.extend(['-G', generation_cmp])
if ogeneration_cmp:
cmd.extend(['-C', ogeneration_cmp])
if sort:
cmd.append('--sort={}'.format(','.join(sort)))
cmd.append(path)
res = __salt__['cmd.run_all'](cmd)
salt.utils.fsutils._verify_run(res)
columns = ('ID', 'gen', 'cgen', 'parent', 'top level', 'otime',
'parent_uuid', 'received_uuid', 'uuid', 'path')
result = []
for line in res['stdout'].splitlines():
table = {}
for key in columns:
value, line = _pop(line, key, key == 'path')
if value:
table[key.lower()] = value
if not line:
result.append(table)
return result |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'diff'},{'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', '11', '14', '24', '28', '237']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'string', 'children': [], 'value': '\'\'\'\n Return the DIFFERENCE of the result sets returned by each matching minion\n pool\n .. versionadded:: 2014.7.0\n These pools are determined from the aggregated and sorted results of\n a salt command.\n This command displays the "diffs" as a series of 2-way differences --\n namely the difference between the FIRST displayed minion pool\n (according to sort order) and EACH SUBSEQUENT minion pool result set.\n Differences are displayed according to the Python ``difflib.unified_diff()``\n as in the case of the salt execution module ``file.get_diff``.\n This command is submitted via a salt runner using the general form::\n salt-run survey.diff [survey_sort=up/down] <target>\n <salt-execution-module> <salt-execution-module parameters>\n Optionally accept a ``survey_sort=`` parameter. Default:\n ``survey_sort=down``\n CLI Example\n .. code-block:: bash\n salt-run survey.diff survey_sort=up "*" cp.get_file_str file:///etc/hosts\n \'\'\''},{'id': '11', 'type': 'import_statement', 'children': ['12']},{'id': '12', 'type': 'dotted_name', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'difflib'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'bulk_ret'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_get_pool_results'},{'id': '19', 'type': 'argument_list', 'children': ['20', '22']},{'id': '20', 'type': 'list_splat', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '22', 'type': 'dictionary_splat', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'is_first_time'},{'id': '27', 'type': 'True', 'children': []},{'id': '28', 'type': 'for_statement', 'children': ['29', '30', '31']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'bulk_ret'},{'id': '31', 'type': 'block', 'children': ['32', '39', '46', '53', '70', '100', '116', '121', '134', '146', '163', '173', '190', '194', '228', '233']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'concatenated_string', 'children': ['37', '38']},{'id': '37', 'type': 'string', 'children': [], 'value': "'minion pool :\\n'"},{'id': '38', 'type': 'string', 'children': [], 'value': "'------------'"},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'subscript', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '45', 'type': 'string', 'children': [], 'value': "'pool'"},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'concatenated_string', 'children': ['51', '52']},{'id': '51', 'type': 'string', 'children': [], 'value': "'pool size :\\n'"},{'id': '52', 'type': 'string', 'children': [], 'value': "'----------'"},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'binary_operator', 'children': ['58', '59'], 'value': '+'},{'id': '58', 'type': 'string', 'children': [], 'value': "' '"},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'text_type'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '69', 'type': 'string', 'children': [], 'value': "'pool'"},{'id': '70', 'type': 'if_statement', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'is_first_time'},{'id': '72', 'type': 'block', 'children': ['73', '77', '84', '95', '99']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'is_first_time'},{'id': '76', 'type': 'False', 'children': []},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'concatenated_string', 'children': ['82', '83']},{'id': '82', 'type': 'string', 'children': [], 'value': "'pool result :\\n'"},{'id': '83', 'type': 'string', 'children': [], 'value': "'------------'"},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '+'},{'id': '89', 'type': 'string', 'children': [], 'value': "' '"},{'id': '90', 'type': 'subscript', 'children': ['91', '94']},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'bulk_ret'},{'id': '93', 'type': 'integer', 'children': [], 'value': '0'},{'id': '94', 'type': 'string', 'children': [], 'value': "'result'"},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '98', 'type': 'argument_list', 'children': []},{'id': '99', 'type': 'continue_statement', 'children': []},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'outs'},{'id': '103', 'type': 'call', 'children': ['104', '108']},{'id': '104', 'type': 'attribute', 'children': ['105', '107']},{'id': '105', 'type': '()', 'children': ['106']},{'id': '106', 'type': 'string', 'children': [], 'value': '\'differences from "{0}" results :\''},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'subscript', 'children': ['110', '115']},{'id': '110', 'type': 'subscript', 'children': ['111', '114']},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'bulk_ret'},{'id': '113', 'type': 'integer', 'children': [], 'value': '0'},{'id': '114', 'type': 'string', 'children': [], 'value': "'pool'"},{'id': '115', 'type': 'integer', 'children': [], 'value': '0'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'outs'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'binary_operator', 'children': ['126', '127'], 'value': '*'},{'id': '126', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '127', 'type': '()', 'children': ['128']},{'id': '128', 'type': 'binary_operator', 'children': ['129', '133'], 'value': '-'},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'outs'},{'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': 'from_result'},{'id': '137', 'type': 'call', 'children': ['138', '145']},{'id': '138', 'type': 'attribute', 'children': ['139', '144']},{'id': '139', 'type': 'subscript', 'children': ['140', '143']},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'bulk_ret'},{'id': '142', 'type': 'integer', 'children': [], 'value': '0'},{'id': '143', 'type': 'string', 'children': [], 'value': "'result'"},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'splitlines'},{'id': '145', 'type': 'argument_list', 'children': []},{'id': '146', 'type': 'for_statement', 'children': ['147', '148', '156']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '150', 'type': 'argument_list', 'children': ['151', '152']},{'id': '151', 'type': 'integer', 'children': [], 'value': '0'},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'from_result'},{'id': '156', 'type': 'block', 'children': ['157']},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'augmented_assignment', 'children': ['159', '162'], 'value': '+='},{'id': '159', 'type': 'subscript', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'from_result'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '162', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'to_result'},{'id': '166', 'type': 'call', 'children': ['167', '172']},{'id': '167', 'type': 'attribute', 'children': ['168', '171']},{'id': '168', 'type': 'subscript', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '170', 'type': 'string', 'children': [], 'value': "'result'"},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'splitlines'},{'id': '172', 'type': 'argument_list', 'children': []},{'id': '173', 'type': 'for_statement', 'children': ['174', '175', '183']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '177', 'type': 'argument_list', 'children': ['178', '179']},{'id': '178', 'type': 'integer', 'children': [], 'value': '0'},{'id': '179', 'type': 'call', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'to_result'},{'id': '183', 'type': 'block', 'children': ['184']},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'augmented_assignment', 'children': ['186', '189'], 'value': '+='},{'id': '186', 'type': 'subscript', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'to_result'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '189', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'outs'},{'id': '193', 'type': 'string', 'children': [], 'value': "''"},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'augmented_assignment', 'children': ['196', '197'], 'value': '+='},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'outs'},{'id': '197', 'type': 'call', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'string', 'children': [], 'value': "''"},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'call', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'difflib'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'unified_diff'},{'id': '206', 'type': 'argument_list', 'children': ['207', '208', '209', '218', '225']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'from_result'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'to_result'},{'id': '209', 'type': 'keyword_argument', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'fromfile'},{'id': '211', 'type': 'subscript', 'children': ['212', '217']},{'id': '212', 'type': 'subscript', 'children': ['213', '216']},{'id': '213', 'type': 'subscript', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'bulk_ret'},{'id': '215', 'type': 'integer', 'children': [], 'value': '0'},{'id': '216', 'type': 'string', 'children': [], 'value': "'pool'"},{'id': '217', 'type': 'integer', 'children': [], 'value': '0'},{'id': '218', 'type': 'keyword_argument', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'tofile'},{'id': '220', 'type': 'subscript', 'children': ['221', '224']},{'id': '221', 'type': 'subscript', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '223', 'type': 'string', 'children': [], 'value': "'pool'"},{'id': '224', 'type': 'integer', 'children': [], 'value': '0'},{'id': '225', 'type': 'keyword_argument', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '227', 'type': 'integer', 'children': [], 'value': '0'},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'call', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'outs'},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'call', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '236', 'type': 'argument_list', 'children': []},{'id': '237', 'type': 'return_statement', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'bulk_ret'} | def diff(*args, **kwargs):
'''
Return the DIFFERENCE of the result sets returned by each matching minion
pool
.. versionadded:: 2014.7.0
These pools are determined from the aggregated and sorted results of
a salt command.
This command displays the "diffs" as a series of 2-way differences --
namely the difference between the FIRST displayed minion pool
(according to sort order) and EACH SUBSEQUENT minion pool result set.
Differences are displayed according to the Python ``difflib.unified_diff()``
as in the case of the salt execution module ``file.get_diff``.
This command is submitted via a salt runner using the general form::
salt-run survey.diff [survey_sort=up/down] <target>
<salt-execution-module> <salt-execution-module parameters>
Optionally accept a ``survey_sort=`` parameter. Default:
``survey_sort=down``
CLI Example
.. code-block:: bash
salt-run survey.diff survey_sort=up "*" cp.get_file_str file:///etc/hosts
'''
import difflib
bulk_ret = _get_pool_results(*args, **kwargs)
is_first_time = True
for k in bulk_ret:
print('minion pool :\n'
'------------')
print(k['pool'])
print('pool size :\n'
'----------')
print(' ' + six.text_type(len(k['pool'])))
if is_first_time:
is_first_time = False
print('pool result :\n'
'------------')
print(' ' + bulk_ret[0]['result'])
print()
continue
outs = ('differences from "{0}" results :').format(
bulk_ret[0]['pool'][0])
print(outs)
print('-' * (len(outs) - 1))
from_result = bulk_ret[0]['result'].splitlines()
for i in range(0, len(from_result)):
from_result[i] += '\n'
to_result = k['result'].splitlines()
for i in range(0, len(to_result)):
to_result[i] += '\n'
outs = ''
outs += ''.join(difflib.unified_diff(from_result,
to_result,
fromfile=bulk_ret[0]['pool'][0],
tofile=k['pool'][0],
n=0))
print(outs)
print()
return bulk_ret |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_pool_results'},{'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', '11', '14', '20', '26', '30', '40', '46', '56', '67', '94', '107', '148', '225', '229', '261']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'string', 'children': [], 'value': '\'\'\'\n A helper function which returns a dictionary of minion pools along with\n their matching result sets.\n Useful for developing other "survey style" functions.\n Optionally accepts a "survey_sort=up" or "survey_sort=down" kwargs for\n specifying sort order.\n Because the kwargs namespace of the "salt" and "survey" command are shared,\n the name "survey_sort" was chosen to help avoid option conflicts.\n \'\'\''},{'id': '11', 'type': 'import_statement', 'children': ['12']},{'id': '12', 'type': 'dotted_name', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'hashlib'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'tgt'},{'id': '17', 'type': 'subscript', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '19', 'type': 'integer', 'children': [], 'value': '0'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '23', 'type': 'subscript', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '25', 'type': 'integer', 'children': [], 'value': '1'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '29', 'type': 'dictionary', 'children': []},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39']},{'id': '38', 'type': 'string', 'children': [], 'value': "'survey_sort'"},{'id': '39', 'type': 'string', 'children': [], 'value': "'down'"},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': '!='},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '45', 'type': 'string', 'children': [], 'value': "'up'"},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'tgt_type'},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '53', 'type': 'argument_list', 'children': ['54', '55']},{'id': '54', 'type': 'string', 'children': [], 'value': "'tgt_type'"},{'id': '55', 'type': 'string', 'children': [], 'value': "'compound'"},{'id': '56', 'type': 'if_statement', 'children': ['57', '62']},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': 'not'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'tgt_type'},{'id': '59', 'type': 'list', 'children': ['60', '61'], 'value': "['compound', 'pcre']"},{'id': '60', 'type': 'string', 'children': [], 'value': "'compound'"},{'id': '61', 'type': 'string', 'children': [], 'value': "'pcre'"},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'tgt_type'},{'id': '66', 'type': 'string', 'children': [], 'value': "'compound'"},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'kwargs_passthru'},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '72', 'type': 'generator_expression', 'children': ['73', '78', '86']},{'id': '73', 'type': 'tuple', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '78', 'type': 'for_in_clause', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'iterkeys'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '86', 'type': 'if_clause', 'children': ['87']},{'id': '87', 'type': 'not_operator', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '97', 'type': 'call', 'children': ['98', '103']},{'id': '98', 'type': 'attribute', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'salt'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'get_local_client'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'subscript', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': '__opts__'},{'id': '106', 'type': 'string', 'children': [], 'value': "'conf_file'"},{'id': '107', 'type': 'try_statement', 'children': ['108', '135']},{'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': 'minions'},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118', '119', '124', '129', '132']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'tgt'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '119', 'type': 'subscript', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '121', 'type': 'slice', 'children': ['122', '123']},{'id': '122', 'type': 'integer', 'children': [], 'value': '2'},{'id': '123', 'type': 'colon', 'children': []},{'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '126', 'type': 'subscript', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': '__opts__'},{'id': '128', 'type': 'string', 'children': [], 'value': "'timeout'"},{'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'tgt_type'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'tgt_type'},{'id': '132', 'type': 'keyword_argument', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'kwarg'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'kwargs_passthru'},{'id': '135', 'type': 'except_clause', 'children': ['136', '140']},{'id': '136', 'type': 'as_pattern', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'SaltClientError'},{'id': '138', 'type': 'as_pattern_target', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'client_error'},{'id': '140', 'type': 'block', 'children': ['141', '146']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'client_error'},{'id': '146', 'type': 'return_statement', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '148', 'type': 'for_statement', 'children': ['149', '150', '154']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'minion'},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'minions'},{'id': '154', 'type': 'block', 'children': ['155', '180', '214']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'digest'},{'id': '158', 'type': 'call', 'children': ['159', '179']},{'id': '159', 'type': 'attribute', 'children': ['160', '178']},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'hashlib'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'sha256'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '176']},{'id': '166', 'type': 'attribute', 'children': ['167', '175']},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'text_type'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'minions'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'minion'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': '__salt_system_encoding__'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'hexdigest'},{'id': '179', 'type': 'argument_list', 'children': []},{'id': '180', 'type': 'if_statement', 'children': ['181', '184']},{'id': '181', 'type': 'comparison_operator', 'children': ['182', '183'], 'value': 'not'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'digest'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '184', 'type': 'block', 'children': ['185', '191', '199']},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '190']},{'id': '187', 'type': 'subscript', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'digest'},{'id': '190', 'type': 'dictionary', 'children': []},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '198']},{'id': '193', 'type': 'subscript', 'children': ['194', '197']},{'id': '194', 'type': 'subscript', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'digest'},{'id': '197', 'type': 'string', 'children': [], 'value': "'pool'"},{'id': '198', 'type': 'list', 'children': [], 'value': '[]'},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '206']},{'id': '201', 'type': 'subscript', 'children': ['202', '205']},{'id': '202', 'type': 'subscript', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'digest'},{'id': '205', 'type': 'string', 'children': [], 'value': "'result'"},{'id': '206', 'type': 'call', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'text_type'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'subscript', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'minions'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'minion'},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'call', 'children': ['216', '223']},{'id': '216', 'type': 'attribute', 'children': ['217', '222']},{'id': '217', 'type': 'subscript', 'children': ['218', '221']},{'id': '218', 'type': 'subscript', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'digest'},{'id': '221', 'type': 'string', 'children': [], 'value': "'pool'"},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'minion'},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'sorted_ret'},{'id': '228', 'type': 'list', 'children': [], 'value': '[]'},{'id': '229', 'type': 'for_statement', 'children': ['230', '231', '251']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '231', 'type': 'call', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '233', 'type': 'argument_list', 'children': ['234', '235', '248']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '235', 'type': 'keyword_argument', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '237', 'type': 'lambda', 'children': ['238', '240']},{'id': '238', 'type': 'lambda_parameters', 'children': ['239']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '240', 'type': 'call', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'subscript', 'children': ['244', '247']},{'id': '244', 'type': 'subscript', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '247', 'type': 'string', 'children': [], 'value': "'pool'"},{'id': '248', 'type': 'keyword_argument', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '251', 'type': 'block', 'children': ['252']},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'call', 'children': ['254', '257']},{'id': '254', 'type': 'attribute', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'sorted_ret'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '257', 'type': 'argument_list', 'children': ['258']},{'id': '258', 'type': 'subscript', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '261', 'type': 'return_statement', 'children': ['262']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'sorted_ret'} | def _get_pool_results(*args, **kwargs):
'''
A helper function which returns a dictionary of minion pools along with
their matching result sets.
Useful for developing other "survey style" functions.
Optionally accepts a "survey_sort=up" or "survey_sort=down" kwargs for
specifying sort order.
Because the kwargs namespace of the "salt" and "survey" command are shared,
the name "survey_sort" was chosen to help avoid option conflicts.
'''
import hashlib
tgt = args[0]
cmd = args[1]
ret = {}
sort = kwargs.pop('survey_sort', 'down')
direction = sort != 'up'
tgt_type = kwargs.pop('tgt_type', 'compound')
if tgt_type not in ['compound', 'pcre']:
tgt_type = 'compound'
kwargs_passthru = dict((k, kwargs[k]) for k in six.iterkeys(kwargs) if not k.startswith('_'))
client = salt.client.get_local_client(__opts__['conf_file'])
try:
minions = client.cmd(tgt, cmd, args[2:], timeout=__opts__['timeout'], tgt_type=tgt_type, kwarg=kwargs_passthru)
except SaltClientError as client_error:
print(client_error)
return ret
for minion in sorted(minions):
digest = hashlib.sha256(six.text_type(minions[minion]).encode(__salt_system_encoding__)).hexdigest()
if digest not in ret:
ret[digest] = {}
ret[digest]['pool'] = []
ret[digest]['result'] = six.text_type(minions[minion])
ret[digest]['pool'].append(minion)
sorted_ret = []
for k in sorted(ret, key=lambda k: len(ret[k]['pool']), reverse=direction):
sorted_ret.append(ret[k])
return sorted_ret |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_'},{'id': '3', 'type': 'parameters', 'children': ['4', '7']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '9', 'type': 'block', 'children': ['10', '12', '18', '28', '45', '57', '65', '70', '74', '90', '118', '138', '148', '183', '209', '237', '341']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'string', 'children': [], 'value': '\'\'\'\n Return a list of all datasets or a specified dataset on the system and the\n values of their used, available, referenced, and mountpoint properties.\n name : string\n name of dataset, volume, or snapshot\n recursive : boolean\n recursively list children\n depth : int\n limit recursion to depth\n properties : string\n comma-separated list of properties to list, the name property will always be added\n type : string\n comma-separated list of types to display, where type is one of\n filesystem, snapshot, volume, bookmark, or all.\n sort : string\n property to sort on (default = name)\n order : string [ascending|descending]\n sort order (default = ascending)\n parsable : boolean\n display numbers in parsable (exact) values\n .. versionadded:: 2018.3.0\n .. versionadded:: 2015.5.0\n CLI Example:\n .. code-block:: bash\n salt \'*\' zfs.list\n salt \'*\' zfs.list myzpool/mydataset [recursive=True|False]\n salt \'*\' zfs.list myzpool/mydataset properties="sharenfs,mountpoint"\n \'\'\''},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'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': 'properties'},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'string', 'children': [], 'value': "'properties'"},{'id': '27', 'type': 'string', 'children': [], 'value': "'used,avail,refer,mountpoint'"},{'id': '28', 'type': 'if_statement', 'children': ['29', '35']},{'id': '29', 'type': 'not_operator', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'string', 'children': [], 'value': "','"},{'id': '45', 'type': 'while_statement', 'children': ['46', '49']},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': 'in'},{'id': '47', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'integer', 'children': [], 'value': '0'},{'id': '64', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '68', 'type': 'list', 'children': ['69'], 'value': "['-H']"},{'id': '69', 'type': 'string', 'children': [], 'value': "'-H'"},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '73', 'type': 'dictionary', 'children': []},{'id': '74', 'type': 'if_statement', 'children': ['75', '82']},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '79', 'type': 'argument_list', 'children': ['80', '81']},{'id': '80', 'type': 'string', 'children': [], 'value': "'recursive'"},{'id': '81', 'type': 'False', 'children': []},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'string', 'children': [], 'value': "'-r'"},{'id': '90', 'type': 'if_statement', 'children': ['91', '106']},{'id': '91', 'type': 'boolean_operator', 'children': ['92', '99'], 'value': 'and'},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '96', 'type': 'argument_list', 'children': ['97', '98']},{'id': '97', 'type': 'string', 'children': [], 'value': "'recursive'"},{'id': '98', 'type': 'False', 'children': []},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '103', 'type': 'argument_list', 'children': ['104', '105']},{'id': '104', 'type': 'string', 'children': [], 'value': "'depth'"},{'id': '105', 'type': 'False', 'children': []},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '112']},{'id': '109', 'type': 'subscript', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '111', 'type': 'string', 'children': [], 'value': "'-d'"},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'string', 'children': [], 'value': "'depth'"},{'id': '118', 'type': 'if_statement', 'children': ['119', '126']},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '123', 'type': 'argument_list', 'children': ['124', '125']},{'id': '124', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '125', 'type': 'False', 'children': []},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '132']},{'id': '129', 'type': 'subscript', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '131', 'type': 'string', 'children': [], 'value': "'-t'"},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'kwargs_sort'},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '145', 'type': 'argument_list', 'children': ['146', '147']},{'id': '146', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '147', 'type': 'False', 'children': []},{'id': '148', 'type': 'if_statement', 'children': ['149', '154']},{'id': '149', 'type': 'boolean_operator', 'children': ['150', '151'], 'value': 'and'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'kwargs_sort'},{'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': 'in'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'kwargs_sort'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'if_statement', 'children': ['156', '168', '175']},{'id': '156', 'type': 'call', 'children': ['157', '166']},{'id': '157', 'type': 'attribute', 'children': ['158', '165']},{'id': '158', 'type': 'call', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '162', 'type': 'argument_list', 'children': ['163', '164']},{'id': '163', 'type': 'string', 'children': [], 'value': "'order'"},{'id': '164', 'type': 'string', 'children': [], 'value': "'ascending'"},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'string', 'children': [], 'value': "'a'"},{'id': '168', 'type': 'block', 'children': ['169']},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '174']},{'id': '171', 'type': 'subscript', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '173', 'type': 'string', 'children': [], 'value': "'-s'"},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'kwargs_sort'},{'id': '175', 'type': 'else_clause', 'children': ['176']},{'id': '176', 'type': 'block', 'children': ['177']},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '182']},{'id': '179', 'type': 'subscript', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '181', 'type': 'string', 'children': [], 'value': "'-S'"},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'kwargs_sort'},{'id': '183', 'type': 'if_statement', 'children': ['184', '189', '201']},{'id': '184', 'type': 'call', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '186', 'type': 'argument_list', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '189', 'type': 'block', 'children': ['190']},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '195']},{'id': '192', 'type': 'subscript', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '194', 'type': 'string', 'children': [], 'value': "'-o'"},{'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': 'identifier', 'children': [], 'value': 'properties'},{'id': '201', 'type': 'else_clause', 'children': ['202']},{'id': '202', 'type': 'block', 'children': ['203']},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'assignment', 'children': ['205', '208']},{'id': '205', 'type': 'subscript', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '207', 'type': 'string', 'children': [], 'value': "'-o'"},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'assignment', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '212', 'type': 'call', 'children': ['213', '216']},{'id': '213', 'type': 'subscript', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': '__salt__'},{'id': '215', 'type': 'string', 'children': [], 'value': "'cmd.run_all'"},{'id': '216', 'type': 'argument_list', 'children': ['217', '234']},{'id': '217', 'type': 'call', 'children': ['218', '221']},{'id': '218', 'type': 'subscript', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': '__utils__'},{'id': '220', 'type': 'string', 'children': [], 'value': "'zfs.zfs_command'"},{'id': '221', 'type': 'argument_list', 'children': ['222', '225', '228', '231']},{'id': '222', 'type': 'keyword_argument', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '224', 'type': 'string', 'children': [], 'value': "'list'"},{'id': '225', 'type': 'keyword_argument', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '228', 'type': 'keyword_argument', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '231', 'type': 'keyword_argument', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '234', 'type': 'keyword_argument', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'python_shell'},{'id': '236', 'type': 'False', 'children': []},{'id': '237', 'type': 'if_statement', 'children': ['238', '243', '332']},{'id': '238', 'type': 'comparison_operator', 'children': ['239', '242'], 'value': '=='},{'id': '239', 'type': 'subscript', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '241', 'type': 'string', 'children': [], 'value': "'retcode'"},{'id': '242', 'type': 'integer', 'children': [], 'value': '0'},{'id': '243', 'type': 'block', 'children': ['244']},{'id': '244', 'type': 'for_statement', 'children': ['245', '246', '253']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'ds'},{'id': '246', 'type': 'call', 'children': ['247', '252']},{'id': '247', 'type': 'attribute', 'children': ['248', '251']},{'id': '248', 'type': 'subscript', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '250', 'type': 'string', 'children': [], 'value': "'stdout'"},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'splitlines'},{'id': '252', 'type': 'argument_list', 'children': []},{'id': '253', 'type': 'block', 'children': ['254', '316', '324']},{'id': '254', 'type': 'if_statement', 'children': ['255', '262', '287']},{'id': '255', 'type': 'call', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '259', 'type': 'argument_list', 'children': ['260', '261']},{'id': '260', 'type': 'string', 'children': [], 'value': "'parsable'"},{'id': '261', 'type': 'True', 'children': []},{'id': '262', 'type': 'block', 'children': ['263']},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'assignment', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'ds_data'},{'id': '266', 'type': 'call', 'children': ['267', '270']},{'id': '267', 'type': 'subscript', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': '__utils__'},{'id': '269', 'type': 'string', 'children': [], 'value': "'zfs.from_auto_dict'"},{'id': '270', 'type': 'argument_list', 'children': ['271']},{'id': '271', 'type': 'call', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '273', 'type': 'argument_list', 'children': ['274']},{'id': '274', 'type': 'call', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '276', 'type': 'argument_list', 'children': ['277']},{'id': '277', 'type': 'call', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '279', 'type': 'argument_list', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '281', 'type': 'call', 'children': ['282', '285']},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'ds'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '285', 'type': 'argument_list', 'children': ['286']},{'id': '286', 'type': 'string', 'children': [], 'value': '"\\t"'},{'id': '287', 'type': 'else_clause', 'children': ['288']},{'id': '288', 'type': 'block', 'children': ['289']},{'id': '289', 'type': 'expression_statement', 'children': ['290']},{'id': '290', 'type': 'assignment', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'ds_data'},{'id': '292', 'type': 'call', 'children': ['293', '296']},{'id': '293', 'type': 'subscript', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': '__utils__'},{'id': '295', 'type': 'string', 'children': [], 'value': "'zfs.to_auto_dict'"},{'id': '296', 'type': 'argument_list', 'children': ['297', '313']},{'id': '297', 'type': 'call', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '299', 'type': 'argument_list', 'children': ['300']},{'id': '300', 'type': 'call', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '302', 'type': 'argument_list', 'children': ['303']},{'id': '303', 'type': 'call', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '305', 'type': 'argument_list', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '307', 'type': 'call', 'children': ['308', '311']},{'id': '308', 'type': 'attribute', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'ds'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '311', 'type': 'argument_list', 'children': ['312']},{'id': '312', 'type': 'string', 'children': [], 'value': '"\\t"'},{'id': '313', 'type': 'keyword_argument', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'convert_to_human'},{'id': '315', 'type': 'True', 'children': []},{'id': '316', 'type': 'expression_statement', 'children': ['317']},{'id': '317', 'type': 'assignment', 'children': ['318', '323']},{'id': '318', 'type': 'subscript', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '320', 'type': 'subscript', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'ds_data'},{'id': '322', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'ds_data'},{'id': '324', 'type': 'delete_statement', 'children': ['325']},{'id': '325', 'type': 'subscript', 'children': ['326', '331']},{'id': '326', 'type': 'subscript', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '328', 'type': 'subscript', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'ds_data'},{'id': '330', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '331', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '332', 'type': 'else_clause', 'children': ['333']},{'id': '333', 'type': 'block', 'children': ['334']},{'id': '334', 'type': 'return_statement', 'children': ['335']},{'id': '335', 'type': 'call', 'children': ['336', '339']},{'id': '336', 'type': 'subscript', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': '__utils__'},{'id': '338', 'type': 'string', 'children': [], 'value': "'zfs.parse_command_result'"},{'id': '339', 'type': 'argument_list', 'children': ['340']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '341', 'type': 'return_statement', 'children': ['342']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'ret'} | def list_(name=None, **kwargs):
'''
Return a list of all datasets or a specified dataset on the system and the
values of their used, available, referenced, and mountpoint properties.
name : string
name of dataset, volume, or snapshot
recursive : boolean
recursively list children
depth : int
limit recursion to depth
properties : string
comma-separated list of properties to list, the name property will always be added
type : string
comma-separated list of types to display, where type is one of
filesystem, snapshot, volume, bookmark, or all.
sort : string
property to sort on (default = name)
order : string [ascending|descending]
sort order (default = ascending)
parsable : boolean
display numbers in parsable (exact) values
.. versionadded:: 2018.3.0
.. versionadded:: 2015.5.0
CLI Example:
.. code-block:: bash
salt '*' zfs.list
salt '*' zfs.list myzpool/mydataset [recursive=True|False]
salt '*' zfs.list myzpool/mydataset properties="sharenfs,mountpoint"
'''
ret = OrderedDict()
properties = kwargs.get('properties', 'used,avail,refer,mountpoint')
if not isinstance(properties, list):
properties = properties.split(',')
while 'name' in properties:
properties.remove('name')
properties.insert(0, 'name')
flags = ['-H']
opts = {}
if kwargs.get('recursive', False):
flags.append('-r')
if kwargs.get('recursive', False) and kwargs.get('depth', False):
opts['-d'] = kwargs.get('depth')
if kwargs.get('type', False):
opts['-t'] = kwargs.get('type')
kwargs_sort = kwargs.get('sort', False)
if kwargs_sort and kwargs_sort in properties:
if kwargs.get('order', 'ascending').startswith('a'):
opts['-s'] = kwargs_sort
else:
opts['-S'] = kwargs_sort
if isinstance(properties, list):
opts['-o'] = ','.join(properties)
else:
opts['-o'] = properties
res = __salt__['cmd.run_all'](
__utils__['zfs.zfs_command'](
command='list',
flags=flags,
opts=opts,
target=name,
),
python_shell=False,
)
if res['retcode'] == 0:
for ds in res['stdout'].splitlines():
if kwargs.get('parsable', True):
ds_data = __utils__['zfs.from_auto_dict'](
OrderedDict(list(zip(properties, ds.split("\t")))),
)
else:
ds_data = __utils__['zfs.to_auto_dict'](
OrderedDict(list(zip(properties, ds.split("\t")))),
convert_to_human=True,
)
ret[ds_data['name']] = ds_data
del ret[ds_data['name']]['name']
else:
return __utils__['zfs.parse_command_result'](res)
return ret |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_users'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '6', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '7', 'type': 'block', 'children': ['8', '10', '14', '28', '37', '45', '114']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'string', 'children': [], 'value': "'''\n Show all users for this company.\n CLI Example:\n salt myminion bamboohr.list_users\n By default, the return data will be keyed by ID. However, it can be ordered\n by any other field. Keep in mind that if the field that is chosen contains\n duplicate values (i.e., location is used, for a company which only has one\n location), then each duplicate value will be overwritten by the previous.\n Therefore, it is advisable to only sort by fields that are guaranteed to be\n unique.\n CLI Examples:\n salt myminion bamboohr.list_users order_by=id\n salt myminion bamboohr.list_users order_by=email\n '''"},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '13', 'type': 'dictionary', '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': 'status'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_query'},{'id': '21', 'type': 'argument_list', 'children': ['22', '25']},{'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '24', 'type': 'string', 'children': [], 'value': "'meta'"},{'id': '25', 'type': 'keyword_argument', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '27', 'type': 'string', 'children': [], 'value': "'users'"},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'ET'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'fromstring'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'getchildren'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'for_statement', 'children': ['46', '47', '48']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '48', 'type': 'block', 'children': ['49', '53', '57', '88', '106']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'user_id'},{'id': '52', 'type': 'None', 'children': []},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'user_ret'},{'id': '56', 'type': 'dictionary', 'children': []},{'id': '57', 'type': 'for_statement', 'children': ['58', '59', '64']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '63', 'type': 'argument_list', 'children': []},{'id': '64', 'type': 'block', 'children': ['65', '75']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '72']},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'user_ret'},{'id': '69', 'type': 'subscript', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '71', 'type': 'integer', 'children': [], 'value': '0'},{'id': '72', 'type': 'subscript', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '74', 'type': 'integer', 'children': [], 'value': '1'},{'id': '75', 'type': 'if_statement', 'children': ['76', '81']},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '80'], 'value': '=='},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '79', 'type': 'integer', 'children': [], 'value': '0'},{'id': '80', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'user_id'},{'id': '85', 'type': 'subscript', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '87', 'type': 'integer', 'children': [], 'value': '1'},{'id': '88', 'type': 'for_statement', 'children': ['89', '90', '95']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'getchildren'},{'id': '94', 'type': 'argument_list', 'children': []},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '103']},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'user_ret'},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '113']},{'id': '108', 'type': 'subscript', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'user_ret'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'user_ret'},{'id': '114', 'type': 'return_statement', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'ret'} | def list_users(order_by='id'):
'''
Show all users for this company.
CLI Example:
salt myminion bamboohr.list_users
By default, the return data will be keyed by ID. However, it can be ordered
by any other field. Keep in mind that if the field that is chosen contains
duplicate values (i.e., location is used, for a company which only has one
location), then each duplicate value will be overwritten by the previous.
Therefore, it is advisable to only sort by fields that are guaranteed to be
unique.
CLI Examples:
salt myminion bamboohr.list_users order_by=id
salt myminion bamboohr.list_users order_by=email
'''
ret = {}
status, result = _query(action='meta', command='users')
root = ET.fromstring(result)
users = root.getchildren()
for user in users:
user_id = None
user_ret = {}
for item in user.items():
user_ret[item[0]] = item[1]
if item[0] == 'id':
user_id = item[1]
for item in user.getchildren():
user_ret[item.tag] = item.text
ret[user_ret[order_by]] = user_ret
return ret |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'key_value'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'minion_id'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'pillar'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'pillar_key'},{'id': '8', 'type': 'string', 'children': [], 'value': "'redis_pillar'"},{'id': '9', 'type': 'block', 'children': ['10', '12', '21', '134']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'string', 'children': [], 'value': "'''\n Looks for key in redis matching minion_id, returns a structure based on the\n data type of the redis key. String for string type, dict for hash type and\n lists for lists, sets and sorted sets.\n pillar_key\n Pillar key to return data into\n '''"},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'key_type'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'subscript', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': '__salt__'},{'id': '18', 'type': 'string', 'children': [], 'value': "'redis.key_type'"},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'minion_id'},{'id': '21', 'type': 'if_statement', 'children': ['22', '25', '36', '51', '85', '100']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': '=='},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'key_type'},{'id': '24', 'type': 'string', 'children': [], 'value': "'string'"},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'return_statement', 'children': ['27']},{'id': '27', 'type': 'dictionary', 'children': ['28']},{'id': '28', 'type': 'pair', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'pillar_key'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'subscript', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': '__salt__'},{'id': '33', 'type': 'string', 'children': [], 'value': "'redis.get_key'"},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'minion_id'},{'id': '36', 'type': 'elif_clause', 'children': ['37', '40']},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': '=='},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'key_type'},{'id': '39', 'type': 'string', 'children': [], 'value': "'hash'"},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'return_statement', 'children': ['42']},{'id': '42', 'type': 'dictionary', 'children': ['43']},{'id': '43', 'type': 'pair', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'pillar_key'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'subscript', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': '__salt__'},{'id': '48', 'type': 'string', 'children': [], 'value': "'redis.hgetall'"},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'minion_id'},{'id': '51', 'type': 'elif_clause', 'children': ['52', '55']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': '=='},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'key_type'},{'id': '54', 'type': 'string', 'children': [], 'value': "'list'"},{'id': '55', 'type': 'block', 'children': ['56', '65', '71']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'list_size'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'subscript', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': '__salt__'},{'id': '62', 'type': 'string', 'children': [], 'value': "'redis.llen'"},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'minion_id'},{'id': '65', 'type': 'if_statement', 'children': ['66', '68']},{'id': '66', 'type': 'not_operator', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'list_size'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'return_statement', 'children': ['70']},{'id': '70', 'type': 'dictionary', 'children': []},{'id': '71', 'type': 'return_statement', 'children': ['72']},{'id': '72', 'type': 'dictionary', 'children': ['73']},{'id': '73', 'type': 'pair', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'pillar_key'},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': '__salt__'},{'id': '78', 'type': 'string', 'children': [], 'value': "'redis.lrange'"},{'id': '79', 'type': 'argument_list', 'children': ['80', '81', '82']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'minion_id'},{'id': '81', 'type': 'integer', 'children': [], 'value': '0'},{'id': '82', 'type': 'binary_operator', 'children': ['83', '84'], 'value': '-'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'list_size'},{'id': '84', 'type': 'integer', 'children': [], 'value': '1'},{'id': '85', 'type': 'elif_clause', 'children': ['86', '89']},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': '=='},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'key_type'},{'id': '88', 'type': 'string', 'children': [], 'value': "'set'"},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'return_statement', 'children': ['91']},{'id': '91', 'type': 'dictionary', 'children': ['92']},{'id': '92', 'type': 'pair', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'pillar_key'},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': '__salt__'},{'id': '97', 'type': 'string', 'children': [], 'value': "'redis.smembers'"},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'minion_id'},{'id': '100', 'type': 'elif_clause', 'children': ['101', '104']},{'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': '=='},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'key_type'},{'id': '103', 'type': 'string', 'children': [], 'value': "'zset'"},{'id': '104', 'type': 'block', 'children': ['105', '114', '120']},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'set_size'},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'subscript', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': '__salt__'},{'id': '111', 'type': 'string', 'children': [], 'value': "'redis.zcard'"},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'minion_id'},{'id': '114', 'type': 'if_statement', 'children': ['115', '117']},{'id': '115', 'type': 'not_operator', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'set_size'},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'return_statement', 'children': ['119']},{'id': '119', 'type': 'dictionary', 'children': []},{'id': '120', 'type': 'return_statement', 'children': ['121']},{'id': '121', 'type': 'dictionary', 'children': ['122']},{'id': '122', 'type': 'pair', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'pillar_key'},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': '__salt__'},{'id': '127', 'type': 'string', 'children': [], 'value': "'redis.zrange'"},{'id': '128', 'type': 'argument_list', 'children': ['129', '130', '131']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'minion_id'},{'id': '130', 'type': 'integer', 'children': [], 'value': '0'},{'id': '131', 'type': 'binary_operator', 'children': ['132', '133'], 'value': '-'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'set_size'},{'id': '133', 'type': 'integer', 'children': [], 'value': '1'},{'id': '134', 'type': 'return_statement', 'children': ['135']},{'id': '135', 'type': 'dictionary', 'children': []} | def key_value(minion_id,
pillar,
pillar_key='redis_pillar'):
'''
Looks for key in redis matching minion_id, returns a structure based on the
data type of the redis key. String for string type, dict for hash type and
lists for lists, sets and sorted sets.
pillar_key
Pillar key to return data into
'''
key_type = __salt__['redis.key_type'](minion_id)
if key_type == 'string':
return {pillar_key: __salt__['redis.get_key'](minion_id)}
elif key_type == 'hash':
return {pillar_key: __salt__['redis.hgetall'](minion_id)}
elif key_type == 'list':
list_size = __salt__['redis.llen'](minion_id)
if not list_size:
return {}
return {pillar_key: __salt__['redis.lrange'](minion_id, 0,
list_size - 1)}
elif key_type == 'set':
return {pillar_key: __salt__['redis.smembers'](minion_id)}
elif key_type == 'zset':
set_size = __salt__['redis.zcard'](minion_id)
if not set_size:
return {}
return {pillar_key: __salt__['redis.zrange'](minion_id, 0,
set_size - 1)}
return {} |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_cmp_version'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'item1'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'item2'},{'id': '6', 'type': 'block', 'children': ['7', '9', '16', '23', '31', '38']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'string', 'children': [], 'value': "'''\n Compare function for package version sorting\n '''"},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'vers1'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': '_LooseVersion'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'item1'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'vers2'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_LooseVersion'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'item2'},{'id': '23', 'type': 'if_statement', 'children': ['24', '27']},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': '<'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'vers1'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'vers2'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'return_statement', 'children': ['29']},{'id': '29', 'type': 'unary_operator', 'children': ['30'], 'value': '-'},{'id': '30', 'type': 'integer', 'children': [], 'value': '1'},{'id': '31', 'type': 'if_statement', 'children': ['32', '35']},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': '>'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'vers1'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'vers2'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'return_statement', 'children': ['37']},{'id': '37', 'type': 'integer', 'children': [], 'value': '1'},{'id': '38', 'type': 'return_statement', 'children': ['39']},{'id': '39', 'type': 'integer', 'children': [], 'value': '0'} | def _cmp_version(item1, item2):
'''
Compare function for package version sorting
'''
vers1 = _LooseVersion(item1)
vers2 = _LooseVersion(item2)
if vers1 < vers2:
return -1
if vers1 > vers2:
return 1
return 0 |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_snapshots'},{'id': '3', 'type': 'parameters', 'children': ['4', '7']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'config_path'},{'id': '6', 'type': 'identifier', 'children': [], 'value': '_DEFAULT_CONFIG_PATH'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sort_by_time'},{'id': '9', 'type': 'False', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '13', '18', '31', '50', '57', '73', '84']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'string', 'children': [], 'value': "'''\n Get a list of all the existing snapshots.\n :param str config_path: The path to the configuration file for the aptly instance.\n :param bool sort_by_time: Whether to sort by creation time instead of by name.\n :return: A list of the snapshot names.\n :rtype: list\n CLI Example:\n .. code-block:: bash\n salt '*' aptly.list_snapshots\n '''"},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': '_validate_config'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'config_path'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '21', 'type': 'list', 'children': ['22', '23', '24', '30'], 'value': "['snapshot', 'list', '-config={}'.format(config_path), '-raw=true']"},{'id': '22', 'type': 'string', 'children': [], 'value': "'snapshot'"},{'id': '23', 'type': 'string', 'children': [], 'value': "'list'"},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'string', 'children': [], 'value': "'-config={}'"},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'config_path'},{'id': '30', 'type': 'string', 'children': [], 'value': "'-raw=true'"},{'id': '31', 'type': 'if_statement', 'children': ['32', '33', '41']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'sort_by_time'},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'string', 'children': [], 'value': "'-sort=time'"},{'id': '41', 'type': 'else_clause', 'children': ['42']},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'string', 'children': [], 'value': "'-sort=name'"},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'cmd_ret'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': '_cmd_run'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '60', 'type': 'list_comprehension', 'children': ['61', '66']},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '65', 'type': 'argument_list', 'children': []},{'id': '66', 'type': 'for_in_clause', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'cmd_ret'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'splitlines'},{'id': '72', 'type': 'argument_list', 'children': []},{'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': 'log'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80']},{'id': '79', 'type': 'string', 'children': [], 'value': "'Found snapshots: %s'"},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '84', 'type': 'return_statement', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'ret'} | def list_snapshots(config_path=_DEFAULT_CONFIG_PATH, sort_by_time=False):
'''
Get a list of all the existing snapshots.
:param str config_path: The path to the configuration file for the aptly instance.
:param bool sort_by_time: Whether to sort by creation time instead of by name.
:return: A list of the snapshot names.
:rtype: list
CLI Example:
.. code-block:: bash
salt '*' aptly.list_snapshots
'''
_validate_config(config_path)
cmd = ['snapshot', 'list', '-config={}'.format(config_path), '-raw=true']
if sort_by_time:
cmd.append('-sort=time')
else:
cmd.append('-sort=name')
cmd_ret = _cmd_run(cmd)
ret = [line.strip() for line in cmd_ret.splitlines()]
log.debug('Found snapshots: %s', len(ret))
return ret |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'render_value'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'if_statement', 'children': ['7', '12', '30', '74']},{'id': '7', 'type': 'call', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '9', 'type': 'argument_list', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'return_statement', 'children': ['14']},{'id': '14', 'type': 'binary_operator', 'children': ['15', '29'], 'value': '+'},{'id': '15', 'type': 'binary_operator', 'children': ['16', '17'], 'value': '+'},{'id': '16', 'type': 'string', 'children': [], 'value': "'['"},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'string', 'children': [], 'value': "', '"},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '21', 'type': 'generator_expression', 'children': ['22', '26']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'render_value'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '26', 'type': 'for_in_clause', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '29', 'type': 'string', 'children': [], 'value': "']'"},{'id': '30', 'type': 'elif_clause', 'children': ['31', '36']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'return_statement', 'children': ['38']},{'id': '38', 'type': '()', 'children': ['39']},{'id': '39', 'type': 'binary_operator', 'children': ['40', '73'], 'value': '+'},{'id': '40', 'type': 'binary_operator', 'children': ['41', '42'], 'value': '+'},{'id': '41', 'type': 'string', 'children': [], 'value': "'{'"},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'string', 'children': [], 'value': "', '"},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '46', 'type': 'generator_expression', 'children': ['47', '61']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'string', 'children': [], 'value': "'{k!r}: {v}'"},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '51', 'type': 'argument_list', 'children': ['52', '55']},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'render_value'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '61', 'type': 'for_in_clause', 'children': ['62', '65']},{'id': '62', 'type': 'pattern_list', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '72', 'type': 'argument_list', 'children': []},{'id': '73', 'type': 'string', 'children': [], 'value': "'}'"},{'id': '74', 'type': 'else_clause', 'children': ['75']},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'return_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'repr'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'value'} | def render_value(value):
if isinstance(value, list):
return '[' + ', '.join(render_value(v) for v in value) + ']'
elif isinstance(value, dict):
return (
'{' +
', '.join('{k!r}: {v}'.format(
k=k, v=render_value(v)) for k, v in sorted(value.items())) +
'}')
else:
return repr(value) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort_schema'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'if_statement', 'children': ['7', '12', '69', '117']},{'id': '7', 'type': 'call', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '9', 'type': 'argument_list', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'for_statement', 'children': ['14', '17', '25']},{'id': '14', 'type': 'pattern_list', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'if_statement', 'children': ['27', '32', '44', '62']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'yield', 'children': ['35']},{'id': '35', 'type': 'expression_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': '_sort_schema'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '44', 'type': 'elif_clause', 'children': ['45', '50']},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'yield', 'children': ['53']},{'id': '53', 'type': 'expression_list', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': '_sort_schema'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '62', 'type': 'else_clause', 'children': ['63']},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'yield', 'children': ['66']},{'id': '66', 'type': 'expression_list', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '69', 'type': 'elif_clause', 'children': ['70', '75']},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'for_statement', 'children': ['77', '78', '79']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'if_statement', 'children': ['81', '86', '96', '112']},{'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': 'v'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'yield', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': '_sort_schema'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '96', 'type': 'elif_clause', 'children': ['97', '102']},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'yield', 'children': ['105']},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': '_sort_schema'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '112', 'type': 'else_clause', 'children': ['113']},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'yield', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '117', 'type': 'else_clause', 'children': ['118']},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'yield', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'd'} | def _sort_schema(schema):
if isinstance(schema, dict):
for k, v in sorted(schema.items()):
if isinstance(v, dict):
yield k, OrderedDict(_sort_schema(v))
elif isinstance(v, list):
yield k, list(_sort_schema(v))
else:
yield k, v
elif isinstance(schema, list):
for v in schema:
if isinstance(v, dict):
yield OrderedDict(_sort_schema(v))
elif isinstance(v, list):
yield list(_sort_schema(v))
else:
yield v
else:
yield d |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort_handlers'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'signals'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'handlers'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'configs'},{'id': '8', 'type': 'block', 'children': ['9', '78', '87', '94', '144', '180']},{'id': '9', 'type': 'function_definition', 'children': ['10', '11', '14']},{'id': '10', 'type': 'function_name', 'children': [], 'value': 'macro_precedence_sorter'},{'id': '11', 'type': 'parameters', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'hname'},{'id': '14', 'type': 'block', 'children': ['15', '21', '29', '50']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '18', 'type': 'subscript', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'configs'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'hname'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'topdown_sort'},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '28'], 'value': 'in'},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'SignalOptions'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'SORT_TOPDOWN'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '29', 'type': 'if_statement', 'children': ['30', '31', '42']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'topdown_sort'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '35', 'type': 'binary_operator', 'children': ['36', '39'], 'value': '-'},{'id': '36', 'type': 'binary_operator', 'children': ['37', '38'], 'value': '-'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'levels_count'},{'id': '38', 'type': 'integer', 'children': [], 'value': '1'},{'id': '39', 'type': 'subscript', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '41', 'type': 'string', 'children': [], 'value': "'level'"},{'id': '42', 'type': 'else_clause', 'children': ['43']},{'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': 'level'},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '49', 'type': 'string', 'children': [], 'value': "'level'"},{'id': '50', 'type': 'if_statement', 'children': ['51', '54', '61', '71']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'in'},{'id': '52', 'type': 'string', 'children': [], 'value': "'begin'"},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'return_statement', 'children': ['56']},{'id': '56', 'type': 'tuple', 'children': ['57', '59', '60']},{'id': '57', 'type': 'unary_operator', 'children': ['58'], 'value': '-'},{'id': '58', 'type': 'integer', 'children': [], 'value': '1'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'hname'},{'id': '61', 'type': 'elif_clause', 'children': ['62', '65']},{'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'in'},{'id': '63', 'type': 'string', 'children': [], 'value': "'end'"},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'return_statement', 'children': ['67']},{'id': '67', 'type': 'tuple', 'children': ['68', '69', '70']},{'id': '68', 'type': 'integer', 'children': [], 'value': '1'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'hname'},{'id': '71', 'type': 'else_clause', 'children': ['72']},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'return_statement', 'children': ['74']},{'id': '74', 'type': 'tuple', 'children': ['75', '76', '77']},{'id': '75', 'type': 'integer', 'children': [], 'value': '0'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'hname'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'levels_count'},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'handlers'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'maps'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'per_signal'},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '94', 'type': 'for_statement', 'children': ['95', '98', '107']},{'id': '95', 'type': 'pattern_list', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'reversed'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'handlers'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'maps'},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'for_statement', 'children': ['109', '112', '117']},{'id': '109', 'type': 'pattern_list', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'hname'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'sig_name'},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '116', 'type': 'argument_list', 'children': []},{'id': '117', 'type': 'block', 'children': ['118', '124']},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'sig_handlers'},{'id': '121', 'type': 'subscript', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'per_signal'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'sig_name'},{'id': '124', 'type': 'if_statement', 'children': ['125', '128']},{'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': 'not'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'hname'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'sig_handlers'},{'id': '128', 'type': 'block', 'children': ['129', '137']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '136']},{'id': '131', 'type': 'subscript', 'children': ['132', '135']},{'id': '132', 'type': 'subscript', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'configs'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'hname'},{'id': '135', 'type': 'string', 'children': [], 'value': "'level'"},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'level'},{'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': 'sig_handlers'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'hname'},{'id': '144', 'type': 'for_statement', 'children': ['145', '148', '153']},{'id': '145', 'type': 'pattern_list', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'sig_name'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'sig_handlers'},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'per_signal'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '152', 'type': 'argument_list', 'children': []},{'id': '153', 'type': 'block', 'children': ['154']},{'id': '154', 'type': 'if_statement', 'children': ['155', '158']},{'id': '155', 'type': 'comparison_operator', 'children': ['156', '157'], 'value': 'in'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'sig_name'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'signals'},{'id': '158', 'type': 'block', 'children': ['159', '167']},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '162', 'type': 'attribute', 'children': ['163', '166']},{'id': '163', 'type': 'subscript', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'signals'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'sig_name'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'flags'},{'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': 'sig_handlers'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'keyword_argument', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'partial'},{'id': '177', 'type': 'argument_list', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'macro_precedence_sorter'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '180', 'type': 'return_statement', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'per_signal'} | def _sort_handlers(cls, signals, handlers, configs):
def macro_precedence_sorter(flags, hname):
data = configs[hname]
topdown_sort = SignalOptions.SORT_TOPDOWN in flags
if topdown_sort:
level = levels_count - 1 - data['level']
else:
level = data['level']
if 'begin' in data:
return (-1, level, hname)
elif 'end' in data:
return (1, level, hname)
else:
return (0, level, hname)
levels_count = len(handlers.maps)
per_signal = defaultdict(list)
for level, m in enumerate(reversed(handlers.maps)):
for hname, sig_name in m.items():
sig_handlers = per_signal[sig_name]
if hname not in sig_handlers:
configs[hname]['level'] = level
sig_handlers.append(hname)
for sig_name, sig_handlers in per_signal.items():
if sig_name in signals:
flags = signals[sig_name].flags
sig_handlers.sort(key=partial(macro_precedence_sorter,
flags))
return per_signal |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_radixPass'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'K'},{'id': '9', 'type': 'block', 'children': ['10', '24', '41', '45', '70']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': '_array'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'string', 'children': [], 'value': '"i"'},{'id': '17', 'type': 'binary_operator', 'children': ['18', '20'], 'value': '*'},{'id': '18', 'type': 'list', 'children': ['19'], 'value': '[0]'},{'id': '19', 'type': 'integer', 'children': [], 'value': '0'},{'id': '20', 'type': '()', 'children': ['21']},{'id': '21', 'type': 'binary_operator', 'children': ['22', '23'], 'value': '+'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'K'},{'id': '23', 'type': 'integer', 'children': [], 'value': '1'},{'id': '24', 'type': 'for_statement', 'children': ['25', '26', '30']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'augmented_assignment', 'children': ['33', '40'], 'value': '+='},{'id': '33', 'type': 'subscript', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '37', 'type': 'subscript', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '40', 'type': 'integer', 'children': [], 'value': '1'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '44', 'type': 'integer', 'children': [], 'value': '0'},{'id': '45', 'type': 'for_statement', 'children': ['46', '47', '53']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'binary_operator', 'children': ['51', '52'], 'value': '+'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'K'},{'id': '52', 'type': 'integer', 'children': [], 'value': '1'},{'id': '53', 'type': 'block', 'children': ['54', '60', '66']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '65']},{'id': '62', 'type': 'subscript', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'augmented_assignment', 'children': ['68', '69'], 'value': '+='},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '70', 'type': 'for_statement', 'children': ['71', '72', '77']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'a_i'},{'id': '72', 'type': 'subscript', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '74', 'type': 'slice', 'children': ['75', '76']},{'id': '75', 'type': 'colon', 'children': []},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '77', 'type': 'block', 'children': ['78', '88']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '87']},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '82', 'type': 'subscript', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'a_i'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'a_i'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'augmented_assignment', 'children': ['90', '95'], 'value': '+='},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'a_i'},{'id': '95', 'type': 'integer', 'children': [], 'value': '1'} | def _radixPass(a, b, r, n, K):
c = _array("i", [0] * (K + 1))
for i in range(n):
c[r[a[i]]] += 1
sum = 0
for i in range(K + 1):
t = c[i]
c[i] = sum
sum += t
for a_i in a[:n]:
b[c[r[a_i]]] = a_i
c[r[a_i]] += 1 |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'save_yaml'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'pretty'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sortkeys'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '23']},{'id': '13', 'type': 'if_statement', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'sortkeys'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '23', 'type': 'with_statement', 'children': ['24', '34']},{'id': '24', 'type': 'with_clause', 'children': ['25']},{'id': '25', 'type': 'with_item', 'children': ['26']},{'id': '26', 'type': 'as_pattern', 'children': ['27', '32']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '31', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '32', 'type': 'as_pattern_target', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'if_statement', 'children': ['36', '37', '46']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'pretty'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'pyaml'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'dump'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '46', 'type': 'else_clause', 'children': ['47']},{'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': 'yaml'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'dump'},{'id': '53', 'type': 'argument_list', 'children': ['54', '55', '56', '59']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'default_flow_style'},{'id': '58', 'type': 'None', 'children': []},{'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'Dumper'},{'id': '61', 'type': 'attribute', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'yamlloader'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'ordereddict'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'CDumper'} | def save_yaml(dictionary, path, pretty=False, sortkeys=False):
if sortkeys:
dictionary = dict(dictionary)
with open(path, 'w') as f:
if pretty:
pyaml.dump(dictionary, f)
else:
yaml.dump(dictionary, f, default_flow_style=None, Dumper=yamlloader.ordereddict.CDumper) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'save_json'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'pretty'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sortkeys'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'with_statement', 'children': ['14', '24']},{'id': '14', 'type': 'with_clause', 'children': ['15']},{'id': '15', 'type': 'with_item', 'children': ['16']},{'id': '16', 'type': 'as_pattern', 'children': ['17', '22']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '21', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '22', 'type': 'as_pattern_target', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '24', 'type': 'block', 'children': ['25', '50']},{'id': '25', 'type': 'if_statement', 'children': ['26', '27', '38']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'pretty'},{'id': '27', 'type': 'block', 'children': ['28', '32']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'indent'},{'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': 'separators'},{'id': '35', 'type': 'tuple', 'children': ['36', '37']},{'id': '36', 'type': 'string', 'children': [], 'value': "','"},{'id': '37', 'type': 'string', 'children': [], 'value': "': '"},{'id': '38', 'type': 'else_clause', 'children': ['39']},{'id': '39', 'type': 'block', 'children': ['40', '44']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'separators'},{'id': '47', 'type': 'tuple', 'children': ['48', '49']},{'id': '48', 'type': 'string', 'children': [], 'value': "', '"},{'id': '49', 'type': 'string', 'children': [], 'value': "': '"},{'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': 'json'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'dump'},{'id': '55', 'type': 'argument_list', 'children': ['56', '57', '58', '61', '64']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'sortkeys'},{'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'separators'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'separators'} | def save_json(dictionary, path, pretty=False, sortkeys=False):
with open(path, 'w') as f:
if pretty:
indent = 2
separators = (',', ': ')
else:
indent = None
separators = (', ', ': ')
json.dump(dictionary, f, indent=indent, sort_keys=sortkeys, separators=separators) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'save_json'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'pretty'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '10', 'type': 'True', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'encoder'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '24', '72', '97']},{'id': '15', 'type': 'if_statement', 'children': ['16', '19']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'encoder'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'encoder'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'DateTimeEncoder'},{'id': '24', 'type': 'if_statement', 'children': ['25', '26', '50']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'pretty'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36', '39', '44', '47']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '38', 'type': 'integer', 'children': [], 'value': '4'},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'separators'},{'id': '41', 'type': 'tuple', 'children': ['42', '43']},{'id': '42', 'type': 'string', 'children': [], 'value': "','"},{'id': '43', 'type': 'string', 'children': [], 'value': "': '"},{'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'encoder'},{'id': '50', 'type': 'else_clause', 'children': ['51']},{'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': 'data'},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '59', 'type': 'argument_list', 'children': ['60', '61', '66', '69']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'separators'},{'id': '63', 'type': 'tuple', 'children': ['64', '65']},{'id': '64', 'type': 'string', 'children': [], 'value': "','"},{'id': '65', 'type': 'string', 'children': [], 'value': "':'"},{'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'encoder'},{'id': '72', 'type': 'if_statement', 'children': ['73', '87']},{'id': '73', 'type': 'boolean_operator', 'children': ['74', '82'], 'value': 'and'},{'id': '74', 'type': 'not_operator', 'children': ['75']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '79'], 'value': '>'},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'version_info'},{'id': '79', 'type': 'tuple', 'children': ['80', '81']},{'id': '80', 'type': 'integer', 'children': [], 'value': '3'},{'id': '81', 'type': 'integer', 'children': [], 'value': '0'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '84', 'type': 'argument_list', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'str'},{'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': 'data'},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'string', 'children': [], 'value': '"utf-8"'},{'id': '97', 'type': 'return_statement', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'data'} | def save_json(val, pretty=False, sort=True, encoder=None):
if encoder is None:
encoder = DateTimeEncoder
if pretty:
data = json.dumps(
val,
indent=4,
separators=(',', ': '),
sort_keys=sort,
cls=encoder
)
else:
data = json.dumps(
val,
separators=(',', ':'),
sort_keys=sort,
cls=encoder
)
if not sys.version_info > (3, 0) and isinstance(data, str):
data = data.decode("utf-8")
return data |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'revdocs2reverts'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '10', '13', '16']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'rev_docs'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'radius'},{'id': '7', 'type': 'attribute', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'RADIUS'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'use_sha1'},{'id': '12', 'type': 'False', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'resort'},{'id': '15', 'type': 'False', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '18', 'type': 'False', 'children': []},{'id': '19', 'type': 'block', 'children': ['20', '36']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'page_rev_docs'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'rev_docs'},{'id': '27', 'type': 'lambda', 'children': ['28', '30']},{'id': '28', 'type': 'lambda_parameters', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'rd'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'rd'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'string', 'children': [], 'value': "'page'"},{'id': '36', 'type': 'for_statement', 'children': ['37', '40', '41']},{'id': '37', 'type': 'pattern_list', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'page_doc'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'rev_docs'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'page_rev_docs'},{'id': '41', 'type': 'block', 'children': ['42', '69', '117', '126', '261']},{'id': '42', 'type': 'if_statement', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '44', 'type': 'block', 'children': ['45', '61']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '52']},{'id': '47', 'type': 'attribute', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'binary_operator', 'children': ['54', '60'], 'value': '+'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'page_doc'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'string', 'children': [], 'value': "'title'"},{'id': '60', 'type': 'string', 'children': [], 'value': '": "'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '68']},{'id': '63', 'type': 'attribute', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '68', 'type': 'argument_list', 'children': []},{'id': '69', 'type': 'if_statement', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'resort'},{'id': '71', 'type': 'block', 'children': ['72', '92']},{'id': '72', 'type': 'if_statement', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '74', 'type': 'block', 'children': ['75', '84']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '82']},{'id': '77', 'type': 'attribute', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'string', 'children': [], 'value': '"(sorting) "'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '91']},{'id': '86', 'type': 'attribute', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '91', 'type': 'argument_list', 'children': []},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'rev_docs'},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '97', 'type': 'argument_list', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'rev_docs'},{'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '101', 'type': 'lambda', 'children': ['102', '104']},{'id': '102', 'type': 'lambda_parameters', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '104', 'type': 'tuple', 'children': ['105', '111']},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'string', 'children': [], 'value': "'timestamp'"},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'detector'},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'Detector'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'radius'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'radius'},{'id': '126', 'type': 'for_statement', 'children': ['127', '128', '129']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'rev_doc'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'rev_docs'},{'id': '129', 'type': 'block', 'children': ['130', '154', '199', '209']},{'id': '130', 'type': 'if_statement', 'children': ['131', '137']},{'id': '131', 'type': 'boolean_operator', 'children': ['132', '134'], 'value': 'and'},{'id': '132', 'type': 'not_operator', 'children': ['133']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'use_sha1'},{'id': '134', 'type': 'comparison_operator', 'children': ['135', '136'], 'value': 'not'},{'id': '135', 'type': 'string', 'children': [], 'value': "'text'"},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'rev_doc'},{'id': '137', 'type': 'block', 'children': ['138', '153']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'string', 'children': [], 'value': '"Skipping {0}: \'text\' field not found in {0}"'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '148', 'type': 'argument_list', 'children': ['149', '152']},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'rev_doc'},{'id': '151', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'rev_doc'},{'id': '153', 'type': 'continue_statement', 'children': []},{'id': '154', 'type': 'if_statement', 'children': ['155', '156', '170']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'use_sha1'},{'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': 'checksum'},{'id': '160', 'type': 'boolean_operator', 'children': ['161', '167'], 'value': 'or'},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'rev_doc'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'string', 'children': [], 'value': "'sha1'"},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'DummyChecksum'},{'id': '169', 'type': 'argument_list', 'children': []},{'id': '170', 'type': 'elif_clause', 'children': ['171', '174']},{'id': '171', 'type': 'comparison_operator', 'children': ['172', '173'], 'value': 'in'},{'id': '172', 'type': 'string', 'children': [], 'value': "'text'"},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'rev_doc'},{'id': '174', 'type': 'block', 'children': ['175', '186']},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'text_bytes'},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '180', 'type': 'argument_list', 'children': ['181', '184', '185']},{'id': '181', 'type': 'subscript', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'rev_doc'},{'id': '183', 'type': 'string', 'children': [], 'value': "'text'"},{'id': '184', 'type': 'string', 'children': [], 'value': "'utf8'"},{'id': '185', 'type': 'string', 'children': [], 'value': "'replace'"},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'checksum'},{'id': '189', 'type': 'call', 'children': ['190', '198']},{'id': '190', 'type': 'attribute', 'children': ['191', '197']},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'hashlib'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'sha1'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'text_bytes'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'digest'},{'id': '198', 'type': 'argument_list', 'children': []},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'revert'},{'id': '202', 'type': 'call', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'detector'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '206', 'type': 'argument_list', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'checksum'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'rev_doc'},{'id': '209', 'type': 'if_statement', 'children': ['210', '211', '239']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'revert'},{'id': '211', 'type': 'block', 'children': ['212', '219']},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'yield', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'revert'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'to_json'},{'id': '218', 'type': 'argument_list', 'children': []},{'id': '219', 'type': 'if_statement', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '221', 'type': 'block', 'children': ['222', '231']},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'call', 'children': ['224', '229']},{'id': '224', 'type': 'attribute', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '229', 'type': 'argument_list', 'children': ['230']},{'id': '230', 'type': 'string', 'children': [], 'value': '"r"'},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'call', 'children': ['233', '238']},{'id': '233', 'type': 'attribute', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '238', 'type': 'argument_list', 'children': []},{'id': '239', 'type': 'else_clause', 'children': ['240']},{'id': '240', 'type': 'block', 'children': ['241']},{'id': '241', 'type': 'if_statement', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '243', 'type': 'block', 'children': ['244', '253']},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'call', 'children': ['246', '251']},{'id': '246', 'type': 'attribute', 'children': ['247', '250']},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '251', 'type': 'argument_list', 'children': ['252']},{'id': '252', 'type': 'string', 'children': [], 'value': '"."'},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'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': 'sys'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '260', 'type': 'argument_list', 'children': []},{'id': '261', 'type': 'if_statement', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '263', 'type': 'block', 'children': ['264', '273']},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'call', 'children': ['266', '271']},{'id': '266', 'type': 'attribute', 'children': ['267', '270']},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'call', 'children': ['275', '280']},{'id': '275', 'type': 'attribute', 'children': ['276', '279']},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '280', 'type': 'argument_list', 'children': []} | def revdocs2reverts(rev_docs, radius=defaults.RADIUS, use_sha1=False,
resort=False, verbose=False):
page_rev_docs = groupby(rev_docs, lambda rd: rd.get('page'))
for page_doc, rev_docs in page_rev_docs:
if verbose:
sys.stderr.write(page_doc.get('title') + ": ")
sys.stderr.flush()
if resort:
if verbose:
sys.stderr.write("(sorting) ")
sys.stderr.flush()
rev_docs = sorted(
rev_docs, key=lambda r: (r.get('timestamp'), r.get('id')))
detector = Detector(radius=radius)
for rev_doc in rev_docs:
if not use_sha1 and 'text' not in rev_doc:
logger.warn("Skipping {0}: 'text' field not found in {0}"
.format(rev_doc['id'], rev_doc))
continue
if use_sha1:
checksum = rev_doc.get('sha1') or DummyChecksum()
elif 'text' in rev_doc:
text_bytes = bytes(rev_doc['text'], 'utf8', 'replace')
checksum = hashlib.sha1(text_bytes).digest()
revert = detector.process(checksum, rev_doc)
if revert:
yield revert.to_json()
if verbose:
sys.stderr.write("r")
sys.stderr.flush()
else:
if verbose:
sys.stderr.write(".")
sys.stderr.flush()
if verbose:
sys.stderr.write("\n")
sys.stderr.flush() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'dsort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'has_header'},{'id': '8', 'type': 'True', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'frow'},{'id': '11', 'type': 'integer', 'children': [], 'value': '0'},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'ofname'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '18', '27', '42', '49']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'ofname'},{'id': '21', 'type': 'conditional_expression', 'children': ['22', '23', '26'], 'value': 'if'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'is'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'ofname'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'ofname'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'CsvFile'},{'id': '32', 'type': 'argument_list', 'children': ['33', '36', '39']},{'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'has_header'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'has_header'},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'frow'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'frow'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'dsort'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '54', 'type': 'argument_list', 'children': ['55', '58', '61']},{'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'ofname'},{'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'has_header'},{'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '63', 'type': 'False', 'children': []} | def dsort(fname, order, has_header=True, frow=0, ofname=None):
r
ofname = fname if ofname is None else ofname
obj = CsvFile(fname=fname, has_header=has_header, frow=frow)
obj.dsort(order)
obj.write(fname=ofname, header=has_header, append=False) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'dsort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '6', 'type': 'block', 'children': ['7', '9', '21', '40', '60', '64', '111']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '12', 'type': 'conditional_expression', 'children': ['13', '14', '19'], 'value': 'if'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '19', 'type': 'list', 'children': ['20'], 'value': '[order]'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'norder'},{'id': '24', 'type': 'list_comprehension', 'children': ['25', '37']},{'id': '25', 'type': 'conditional_expression', 'children': ['26', '30', '36'], 'value': 'if'},{'id': '26', 'type': 'dictionary', 'children': ['27']},{'id': '27', 'type': 'pair', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '29', 'type': 'string', 'children': [], 'value': '"A"'},{'id': '30', 'type': 'not_operator', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '37', 'type': 'for_in_clause', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'order'},{'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': 'self'},{'id': '44', 'type': 'identifier', 'children': [], 'value': '_in_header'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'list_comprehension', 'children': ['47', '57']},{'id': '47', 'type': 'subscript', 'children': ['48', '56']},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '55', 'type': 'argument_list', 'children': []},{'id': '56', 'type': 'integer', 'children': [], 'value': '0'},{'id': '57', 'type': 'for_in_clause', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'norder'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'clist'},{'id': '63', 'type': 'list', 'children': [], 'value': '[]'},{'id': '64', 'type': 'for_statement', 'children': ['65', '66', '67']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'nitem'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'norder'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'for_statement', 'children': ['69', '72', '77']},{'id': '69', 'type': 'pattern_list', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'nitem'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '76', 'type': 'argument_list', 'children': []},{'id': '77', 'type': 'block', 'children': ['78']},{'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': 'clist'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'tuple', 'children': ['85', '104']},{'id': '85', 'type': 'conditional_expression', 'children': ['86', '87', '92'], 'value': 'if'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '89', 'type': 'argument_list', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '92', 'type': 'call', 'children': ['93', '98']},{'id': '93', 'type': 'attribute', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '96', 'type': 'identifier', 'children': [], 'value': '_header_upper'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '103', 'type': 'argument_list', 'children': []},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '110'], 'value': '=='},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '109', 'type': 'argument_list', 'children': []},{'id': '110', 'type': 'string', 'children': [], 'value': '"D"'},{'id': '111', 'type': 'for_statement', 'children': ['112', '115', '119']},{'id': '112', 'type': 'tuple_pattern', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'cindex'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'rvalue'},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'reversed'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'clist'},{'id': '119', 'type': 'block', 'children': ['120', '129']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'fpointer'},{'id': '123', 'type': 'call', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'itemgetter'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'cindex'},{'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': '_data'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '136', 'type': 'argument_list', 'children': ['137', '140']},{'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'fpointer'},{'id': '140', 'type': 'keyword_argument', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'rvalue'} | def dsort(self, order):
r
order = order if isinstance(order, list) else [order]
norder = [{item: "A"} if not isinstance(item, dict) else item for item in order]
self._in_header([list(item.keys())[0] for item in norder])
clist = []
for nitem in norder:
for key, value in nitem.items():
clist.append(
(
key
if isinstance(key, int)
else self._header_upper.index(key.upper()),
value.upper() == "D",
)
)
for (cindex, rvalue) in reversed(clist):
fpointer = operator.itemgetter(cindex)
self._data.sort(key=fpointer, reverse=rvalue) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '30']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_points_and_weights'},{'id': '3', 'type': 'parameters', 'children': ['4', '17', '21', '24', '27']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'w_func'},{'id': '6', 'type': 'lambda', 'children': ['7', '9']},{'id': '7', 'type': 'lambda_parameters', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'ones'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'left'},{'id': '19', 'type': 'unary_operator', 'children': ['20'], 'value': '-'},{'id': '20', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'right'},{'id': '23', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'num_points'},{'id': '26', 'type': 'integer', 'children': [], 'value': '5'},{'id': '27', 'type': 'default_parameter', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '29', 'type': 'integer', 'children': [], 'value': '4096'},{'id': '30', 'type': 'block', 'children': ['31', '43', '67', '76', '87', '91', '100', '109', '122', '134', '147', '155', '161', '177', '183']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'dx'},{'id': '34', 'type': 'binary_operator', 'children': ['35', '42'], 'value': '/'},{'id': '35', 'type': '()', 'children': ['36']},{'id': '36', 'type': 'binary_operator', 'children': ['37', '41'], 'value': '-'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'right'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'left'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'hstack'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'linspace'},{'id': '55', 'type': 'argument_list', 'children': ['56', '61', '66']},{'id': '56', 'type': 'binary_operator', 'children': ['57', '58'], 'value': '+'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'left'},{'id': '58', 'type': 'binary_operator', 'children': ['59', '60'], 'value': '*'},{'id': '59', 'type': 'float', 'children': [], 'value': '0.5'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'dx'},{'id': '61', 'type': 'binary_operator', 'children': ['62', '63'], 'value': '-'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'right'},{'id': '63', 'type': 'binary_operator', 'children': ['64', '65'], 'value': '*'},{'id': '64', 'type': 'float', 'children': [], 'value': '0.5'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'dx'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '70', 'type': 'binary_operator', 'children': ['71', '72'], 'value': '*'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'dx'},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'w_func'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '81']},{'id': '78', 'type': 'tuple_pattern', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'discrete_gautschi'},{'id': '83', 'type': 'argument_list', 'children': ['84', '85', '86']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'num_points'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'beta'},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'sqrt'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'J'},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'diag'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'augmented_assignment', 'children': ['111', '112'], 'value': '+='},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'J'},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'diag'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'beta'},{'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '120', 'type': 'unary_operator', 'children': ['121'], 'value': '-'},{'id': '121', 'type': 'integer', 'children': [], 'value': '1'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'augmented_assignment', 'children': ['124', '125'], 'value': '+='},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'J'},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'diag'},{'id': '129', 'type': 'argument_list', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'beta'},{'id': '131', 'type': 'keyword_argument', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '133', 'type': 'integer', 'children': [], 'value': '1'},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '139']},{'id': '136', 'type': 'tuple_pattern', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'points'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '139', 'type': 'call', 'children': ['140', '145']},{'id': '140', 'type': 'attribute', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'linalg'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'eigh'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'J'},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'points'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '154', 'type': 'argument_list', 'children': []},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'points'},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'points'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '164', 'type': 'binary_operator', 'children': ['165', '172'], 'value': '*'},{'id': '165', 'type': 'binary_operator', 'children': ['166', '171'], 'value': '**'},{'id': '166', 'type': 'subscript', 'children': ['167', '168', '169']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '168', 'type': 'integer', 'children': [], 'value': '0'},{'id': '169', 'type': 'slice', 'children': ['170']},{'id': '170', 'type': 'colon', 'children': []},{'id': '171', 'type': 'integer', 'children': [], 'value': '2'},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '176', 'type': 'argument_list', 'children': []},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '180', 'type': 'subscript', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '183', 'type': 'return_statement', 'children': ['184']},{'id': '184', 'type': 'tuple', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'points'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'weights'} | def get_points_and_weights(w_func=lambda x : np.ones(x.shape),
left=-1.0, right=1.0, num_points=5, n=4096):
dx = (float(right)-left)/n
z = np.hstack(np.linspace(left+0.5*dx, right-0.5*dx, n))
w = dx*w_func(z)
(a, b) = discrete_gautschi(z, w, num_points)
alpha = a
beta = np.sqrt(b)
J = np.diag(alpha)
J += np.diag(beta, k=-1)
J += np.diag(beta, k=1)
(points,v) = np.linalg.eigh(J)
ind = points.argsort()
points = points[ind]
weights = v[0,:]**2 * w.sum()
weights = weights[ind]
return (points, weights) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'apply_to'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '51']},{'id': '10', 'type': 'if_statement', 'children': ['11', '37']},{'id': '11', 'type': 'boolean_operator', 'children': ['12', '36'], 'value': 'and'},{'id': '12', 'type': 'boolean_operator', 'children': ['13', '29'], 'value': 'and'},{'id': '13', 'type': 'boolean_operator', 'children': ['14', '21'], 'value': 'and'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'ndarray'},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '28'], 'value': '=='},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '28', 'type': 'integer', 'children': [], 'value': '2'},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '35'], 'value': '=='},{'id': '30', 'type': 'subscript', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '34', 'type': 'integer', 'children': [], 'value': '0'},{'id': '35', 'type': 'integer', 'children': [], 'value': '3'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'return_statement', 'children': ['39']},{'id': '39', 'type': 'binary_operator', 'children': ['40', '41'], 'value': '+'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '41', 'type': 'call', 'children': ['42', '47']},{'id': '42', 'type': 'attribute', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'reshape'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'tuple', 'children': ['49', '50']},{'id': '49', 'type': 'integer', 'children': [], 'value': '3'},{'id': '50', 'type': 'integer', 'children': [], 'value': '1'},{'id': '51', 'type': 'if_statement', 'children': ['52', '88', '95', '116', '134', '151', '160']},{'id': '52', 'type': 'boolean_operator', 'children': ['53', '86'], 'value': 'and'},{'id': '53', 'type': 'boolean_operator', 'children': ['54', '61'], 'value': 'and'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ndarray'},{'id': '61', 'type': '()', 'children': ['62']},{'id': '62', 'type': 'boolean_operator', 'children': ['63', '69'], 'value': 'or'},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '67'], 'value': '=='},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '67', 'type': 'tuple', 'children': ['68']},{'id': '68', 'type': 'integer', 'children': [], 'value': '3'},{'id': '69', 'type': '()', 'children': ['70']},{'id': '70', 'type': 'boolean_operator', 'children': ['71', '79'], 'value': 'and'},{'id': '71', 'type': 'comparison_operator', 'children': ['72', '78'], 'value': '=='},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '78', 'type': 'integer', 'children': [], 'value': '2'},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '85'], 'value': '=='},{'id': '80', 'type': 'subscript', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '84', 'type': 'integer', 'children': [], 'value': '1'},{'id': '85', 'type': 'integer', 'children': [], 'value': '3'},{'id': '86', 'type': 'not_operator', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'return_statement', 'children': ['90']},{'id': '90', 'type': 'binary_operator', 'children': ['91', '92'], 'value': '+'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '95', 'type': 'elif_clause', 'children': ['96', '101']},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '98', 'type': 'argument_list', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'Complete'},{'id': '101', 'type': 'block', 'children': ['102']},{'id': '102', 'type': 'return_statement', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'Complete'},{'id': '105', 'type': 'argument_list', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '109', 'type': 'binary_operator', 'children': ['110', '113'], 'value': '+'},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '116', 'type': 'elif_clause', 'children': ['117', '122']},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '119', 'type': 'argument_list', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'Translation'},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'return_statement', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'Translation'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'binary_operator', 'children': ['128', '131'], 'value': '+'},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '134', 'type': 'elif_clause', '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': 'x'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'Rotation'},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'return_statement', 'children': ['142']},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'Complete'},{'id': '144', 'type': 'argument_list', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '151', 'type': 'elif_clause', 'children': ['152', '157']},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '154', 'type': 'argument_list', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'UnitCell'},{'id': '157', 'type': 'block', 'children': ['158']},{'id': '158', 'type': 'return_statement', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '160', 'type': 'else_clause', 'children': ['161']},{'id': '161', 'type': 'block', 'children': ['162']},{'id': '162', 'type': 'raise_statement', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'binary_operator', 'children': ['167', '168'], 'value': '%'},{'id': '167', 'type': 'string', 'children': [], 'value': '"Can not apply this translation to %s"'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'x'} | def apply_to(self, x, columns=False):
if isinstance(x, np.ndarray) and len(x.shape) == 2 and x.shape[0] == 3 and columns:
return x + self.t.reshape((3,1))
if isinstance(x, np.ndarray) and (x.shape == (3, ) or (len(x.shape) == 2 and x.shape[1] == 3)) and not columns:
return x + self.t
elif isinstance(x, Complete):
return Complete(x.r, x.t + self.t)
elif isinstance(x, Translation):
return Translation(x.t + self.t)
elif isinstance(x, Rotation):
return Complete(x.r, self.t)
elif isinstance(x, UnitCell):
return x
else:
raise ValueError("Can not apply this translation to %s" % x) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'apply_to'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '48']},{'id': '10', 'type': 'if_statement', 'children': ['11', '37']},{'id': '11', 'type': 'boolean_operator', 'children': ['12', '36'], 'value': 'and'},{'id': '12', 'type': 'boolean_operator', 'children': ['13', '29'], 'value': 'and'},{'id': '13', 'type': 'boolean_operator', 'children': ['14', '21'], 'value': 'and'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'ndarray'},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '28'], 'value': '=='},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '28', 'type': 'integer', 'children': [], 'value': '2'},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '35'], 'value': '=='},{'id': '30', 'type': 'subscript', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '34', 'type': 'integer', 'children': [], 'value': '0'},{'id': '35', 'type': 'integer', 'children': [], 'value': '3'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'return_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'dot'},{'id': '43', 'type': 'argument_list', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '48', 'type': 'if_statement', 'children': ['49', '85', '100', '133', '158', '180', '205']},{'id': '49', 'type': 'boolean_operator', 'children': ['50', '83'], 'value': 'and'},{'id': '50', 'type': 'boolean_operator', 'children': ['51', '58'], 'value': 'and'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '53', 'type': 'argument_list', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'ndarray'},{'id': '58', 'type': '()', 'children': ['59']},{'id': '59', 'type': 'boolean_operator', 'children': ['60', '66'], 'value': 'or'},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '64'], 'value': '=='},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '64', 'type': 'tuple', 'children': ['65']},{'id': '65', 'type': 'integer', 'children': [], 'value': '3'},{'id': '66', 'type': '()', 'children': ['67']},{'id': '67', 'type': 'boolean_operator', 'children': ['68', '76'], 'value': 'and'},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '75'], 'value': '=='},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '75', 'type': 'integer', 'children': [], 'value': '2'},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '82'], 'value': '=='},{'id': '77', 'type': 'subscript', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '81', 'type': 'integer', 'children': [], 'value': '1'},{'id': '82', 'type': 'integer', 'children': [], 'value': '3'},{'id': '83', 'type': 'not_operator', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'return_statement', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'dot'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '93', 'type': 'call', 'children': ['94', '99']},{'id': '94', 'type': 'attribute', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'transpose'},{'id': '99', 'type': 'argument_list', 'children': []},{'id': '100', 'type': 'elif_clause', 'children': ['101', '106']},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '103', 'type': 'argument_list', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'Complete'},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'return_statement', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'Complete'},{'id': '110', 'type': 'argument_list', 'children': ['111', '122']},{'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': 'dot'},{'id': '115', 'type': 'argument_list', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'dot'},{'id': '126', 'type': 'argument_list', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '133', 'type': 'elif_clause', 'children': ['134', '139']},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '136', 'type': 'argument_list', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'Translation'},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'return_statement', 'children': ['141']},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'Complete'},{'id': '143', 'type': 'argument_list', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'dot'},{'id': '151', 'type': 'argument_list', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '158', 'type': 'elif_clause', 'children': ['159', '164']},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '161', 'type': 'argument_list', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'Rotation'},{'id': '164', 'type': 'block', 'children': ['165']},{'id': '165', 'type': 'return_statement', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'Rotation'},{'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': 'np'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'dot'},{'id': '173', 'type': 'argument_list', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '180', 'type': 'elif_clause', 'children': ['181', '186']},{'id': '181', 'type': 'call', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '183', 'type': 'argument_list', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'UnitCell'},{'id': '186', 'type': 'block', 'children': ['187']},{'id': '187', 'type': 'return_statement', 'children': ['188']},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'UnitCell'},{'id': '190', 'type': 'argument_list', 'children': ['191', '202']},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'dot'},{'id': '195', 'type': 'argument_list', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'active'},{'id': '205', 'type': 'else_clause', 'children': ['206']},{'id': '206', 'type': 'block', 'children': ['207']},{'id': '207', 'type': 'raise_statement', 'children': ['208']},{'id': '208', 'type': 'call', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'binary_operator', 'children': ['212', '213'], 'value': '%'},{'id': '212', 'type': 'string', 'children': [], 'value': '"Can not apply this rotation to %s"'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'x'} | def apply_to(self, x, columns=False):
if isinstance(x, np.ndarray) and len(x.shape) == 2 and x.shape[0] == 3 and columns:
return np.dot(self.r, x)
if isinstance(x, np.ndarray) and (x.shape == (3, ) or (len(x.shape) == 2 and x.shape[1] == 3)) and not columns:
return np.dot(x, self.r.transpose())
elif isinstance(x, Complete):
return Complete(np.dot(self.r, x.r), np.dot(self.r, x.t))
elif isinstance(x, Translation):
return Complete(self.r, np.dot(self.r, x.t))
elif isinstance(x, Rotation):
return Rotation(np.dot(self.r, x.r))
elif isinstance(x, UnitCell):
return UnitCell(np.dot(self.r, x.matrix), x.active)
else:
raise ValueError("Can not apply this rotation to %s" % x) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'canonical_order'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '46', '99', '108', '142']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'starting_vertex'},{'id': '9', 'type': 'subscript', 'children': ['10', '44']},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '12', 'type': 'generator_expression', 'children': ['13', '39']},{'id': '13', 'type': 'tuple', 'children': ['14', '23', '29', '38']},{'id': '14', 'type': 'unary_operator', 'children': ['15'], 'value': '-'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'subscript', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'equivalent_vertices'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'vertex'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'get_vertex_string'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'vertex'},{'id': '29', 'type': 'call', 'children': ['30', '37']},{'id': '30', 'type': 'attribute', 'children': ['31', '36']},{'id': '31', 'type': 'subscript', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'vertex_fingerprints'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'vertex'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'tobytes'},{'id': '37', 'type': 'argument_list', 'children': []},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'vertex'},{'id': '39', 'type': 'for_in_clause', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'vertex'},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'central_vertices'},{'id': '44', 'type': 'unary_operator', 'children': ['45'], 'value': '-'},{'id': '45', 'type': 'integer', 'children': [], 'value': '1'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '49', 'type': 'list_comprehension', 'children': ['50', '78', '88']},{'id': '50', 'type': 'list', 'children': ['51', '53', '62', '68', '77'], 'value': '[\n -distance,\n -len(self.equivalent_vertices[vertex]),\n self.get_vertex_string(vertex),\n self.vertex_fingerprints[vertex].tobytes(),\n vertex\n ]'},{'id': '51', 'type': 'unary_operator', 'children': ['52'], 'value': '-'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '53', 'type': 'unary_operator', 'children': ['54'], 'value': '-'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'subscript', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'equivalent_vertices'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'vertex'},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'get_vertex_string'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'vertex'},{'id': '68', 'type': 'call', 'children': ['69', '76']},{'id': '69', 'type': 'attribute', 'children': ['70', '75']},{'id': '70', 'type': 'subscript', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'vertex_fingerprints'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'vertex'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'tobytes'},{'id': '76', 'type': 'argument_list', 'children': []},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'vertex'},{'id': '78', 'type': 'for_in_clause', 'children': ['79', '82']},{'id': '79', 'type': 'pattern_list', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'vertex'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'iter_breadth_first'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'starting_vertex'},{'id': '88', 'type': 'if_clause', 'children': ['89']},{'id': '89', 'type': 'comparison_operator', 'children': ['90', '98'], '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': 'subscript', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'neighbors'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'vertex'},{'id': '98', 'type': 'integer', 'children': [], 'value': '0'},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '107', 'type': 'True', 'children': []},{'id': '108', 'type': 'for_statement', 'children': ['109', '110', '118']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '112', 'type': 'argument_list', 'children': ['113', '114']},{'id': '113', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'l'},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'if_statement', 'children': ['120', '139']},{'id': '120', 'type': 'comparison_operator', 'children': ['121', '129'], 'value': '=='},{'id': '121', 'type': 'subscript', 'children': ['122', '125']},{'id': '122', 'type': 'subscript', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '125', 'type': 'slice', 'children': ['126', '127']},{'id': '126', 'type': 'colon', 'children': []},{'id': '127', 'type': 'unary_operator', 'children': ['128'], 'value': '-'},{'id': '128', 'type': 'integer', 'children': [], 'value': '1'},{'id': '129', 'type': 'subscript', 'children': ['130', '135']},{'id': '130', 'type': 'subscript', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '132', 'type': 'binary_operator', 'children': ['133', '134'], 'value': '-'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '134', 'type': 'integer', 'children': [], 'value': '1'},{'id': '135', 'type': 'slice', 'children': ['136', '137']},{'id': '136', 'type': 'colon', 'children': []},{'id': '137', 'type': 'unary_operator', 'children': ['138'], 'value': '-'},{'id': '138', 'type': 'integer', 'children': [], 'value': '1'},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'raise_statement', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'},{'id': '142', 'type': 'return_statement', 'children': ['143']},{'id': '143', 'type': 'list_comprehension', 'children': ['144', '148']},{'id': '144', 'type': 'subscript', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '146', 'type': 'unary_operator', 'children': ['147'], 'value': '-'},{'id': '147', 'type': 'integer', 'children': [], 'value': '1'},{'id': '148', 'type': 'for_in_clause', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'l'} | def canonical_order(self):
starting_vertex = max(
(
-len(self.equivalent_vertices[vertex]),
self.get_vertex_string(vertex),
self.vertex_fingerprints[vertex].tobytes(),
vertex
) for vertex in self.central_vertices
)[-1]
l = [
[
-distance,
-len(self.equivalent_vertices[vertex]),
self.get_vertex_string(vertex),
self.vertex_fingerprints[vertex].tobytes(),
vertex
] for vertex, distance in self.iter_breadth_first(starting_vertex)
if len(self.neighbors[vertex]) > 0
]
l.sort(reverse=True)
for i in range(1, len(l)):
if l[i][:-1] == l[i-1][:-1]:
raise NotImplementedError
return [record[-1] for record in l] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_subgraph'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'subvertices'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'normalize'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '261']},{'id': '10', 'type': 'if_statement', 'children': ['11', '12', '192']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'normalize'},{'id': '12', 'type': 'block', 'children': ['13', '30', '34', '38', '97', '110', '131', '141', '151', '164', '178']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'revorder'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '18', 'type': 'generator_expression', 'children': ['19', '22']},{'id': '19', 'type': 'tuple', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '22', 'type': 'for_in_clause', 'children': ['23', '26']},{'id': '23', 'type': 'pattern_list', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'subvertices'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'new_edges'},{'id': '33', 'type': 'list', 'children': [], 'value': '[]'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'old_edge_indexes'},{'id': '37', 'type': 'list', 'children': [], 'value': '[]'},{'id': '38', 'type': 'for_statement', 'children': ['39', '44', '50']},{'id': '39', 'type': 'pattern_list', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'counter'},{'id': '41', 'type': 'tuple_pattern', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'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': 'edges'},{'id': '50', 'type': 'block', 'children': ['51', '60', '66', '75', '81', '90']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'new_i'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'revorder'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '60', 'type': 'if_statement', 'children': ['61', '64']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'is'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'new_i'},{'id': '63', 'type': 'None', 'children': []},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'continue_statement', 'children': []},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'new_j'},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'revorder'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '75', 'type': 'if_statement', 'children': ['76', '79']},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': 'is'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'new_j'},{'id': '78', 'type': 'None', 'children': []},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'continue_statement', 'children': []},{'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': 'new_edges'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'tuple', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'new_i'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'new_j'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'old_edge_indexes'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'counter'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'new_edges'},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '118', 'type': '()', 'children': ['119']},{'id': '119', 'type': 'lambda', 'children': ['120', '122']},{'id': '120', 'type': 'lambda_parameters', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'new_edges'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'new_edges'},{'id': '134', 'type': 'list_comprehension', 'children': ['135', '138']},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'new_edges'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '138', 'type': 'for_in_clause', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'old_edge_indexes'},{'id': '144', 'type': 'list_comprehension', 'children': ['145', '148']},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'old_edge_indexes'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '148', 'type': 'for_in_clause', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'Graph'},{'id': '156', 'type': 'argument_list', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'new_edges'},{'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'num_vertices'},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'subvertices'},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '168', 'type': 'identifier', 'children': [], 'value': '_old_vertex_indexes'},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '173', 'type': 'argument_list', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'subvertices'},{'id': '175', 'type': 'keyword_argument', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '182', 'type': 'identifier', 'children': [], 'value': '_old_edge_indexes'},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '187', 'type': 'argument_list', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'old_edge_indexes'},{'id': '189', 'type': 'keyword_argument', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '192', 'type': 'else_clause', 'children': ['193']},{'id': '193', 'type': 'block', 'children': ['194', '201', '231', '245', '255']},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'subvertices'},{'id': '197', 'type': 'call', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'subvertices'},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'old_edge_indexes'},{'id': '204', 'type': 'call', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '208', 'type': 'argument_list', 'children': ['209', '228']},{'id': '209', 'type': 'list_comprehension', 'children': ['210', '211', '221']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '211', 'type': 'for_in_clause', 'children': ['212', '215']},{'id': '212', 'type': 'pattern_list', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '215', 'type': 'call', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'edges'},{'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': 'edge'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'issubset'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'subvertices'},{'id': '228', 'type': 'keyword_argument', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'new_edges'},{'id': '234', 'type': 'call', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '236', 'type': 'generator_expression', 'children': ['237', '242']},{'id': '237', 'type': 'subscript', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '242', 'type': 'for_in_clause', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'old_edge_indexes'},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'assignment', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '248', 'type': 'call', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'Graph'},{'id': '250', 'type': 'argument_list', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'new_edges'},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'num_vertices'},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'assignment', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '259', 'type': 'identifier', 'children': [], 'value': '_old_edge_indexes'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'old_edge_indexes'},{'id': '261', 'type': 'return_statement', 'children': ['262']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'result'} | def get_subgraph(self, subvertices, normalize=False):
if normalize:
revorder = dict((j, i) for i, j in enumerate(subvertices))
new_edges = []
old_edge_indexes = []
for counter, (i, j) in enumerate(self.edges):
new_i = revorder.get(i)
if new_i is None:
continue
new_j = revorder.get(j)
if new_j is None:
continue
new_edges.append((new_i, new_j))
old_edge_indexes.append(counter)
order = list(range(len(new_edges)))
order.sort( key=(lambda i: tuple(sorted(new_edges[i]))) )
new_edges = [new_edges[i] for i in order]
old_edge_indexes = [old_edge_indexes[i] for i in order]
result = Graph(new_edges, num_vertices=len(subvertices))
result._old_vertex_indexes = np.array(subvertices, dtype=int)
result._old_edge_indexes = np.array(old_edge_indexes, dtype=int)
else:
subvertices = set(subvertices)
old_edge_indexes = np.array([
i for i, edge in enumerate(self.edges)
if edge.issubset(subvertices)
], dtype=int)
new_edges = tuple(self.edges[i] for i in old_edge_indexes)
result = Graph(new_edges, self.num_vertices)
result._old_edge_indexes = old_edge_indexes
return result |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_closed_cycles'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '23', '44', '48', '154', '160', '173']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'closed_cycles'},{'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': 'todo'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '15', 'type': 'argument_list', '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': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'forward'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '22', 'type': 'argument_list', 'children': []},{'id': '23', 'type': 'if_statement', 'children': ['24', '36']},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': '!='},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'todo'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '35']},{'id': '30', 'type': 'attribute', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'forward'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '35', 'type': 'argument_list', 'children': []},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'raise_statement', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'GraphError'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'concatenated_string', 'children': ['42', '43']},{'id': '42', 'type': 'string', 'children': [], 'value': '"The subject and pattern graph must have the same "'},{'id': '43', 'type': 'string', 'children': [], 'value': '"numbering."'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'current_vertex'},{'id': '47', 'type': 'None', 'children': []},{'id': '48', 'type': 'while_statement', 'children': ['49', '55']},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '54'], 'value': '>'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'todo'},{'id': '54', 'type': 'integer', 'children': [], 'value': '0'},{'id': '55', 'type': 'block', 'children': ['56', '82', '89', '98']},{'id': '56', 'type': 'if_statement', 'children': ['57', '60', '73']},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': '=='},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'current_vertex'},{'id': '59', 'type': 'None', 'children': []},{'id': '60', 'type': 'block', 'children': ['61', '69']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'current_vertex'},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'todo'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '68', 'type': 'argument_list', 'children': []},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'current_cycle'},{'id': '72', 'type': 'list', 'children': [], 'value': '[]'},{'id': '73', 'type': 'else_clause', 'children': ['74']},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'todo'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'discard'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'current_vertex'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'current_cycle'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'current_vertex'},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'next_vertex'},{'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_destination'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'current_vertex'},{'id': '98', 'type': 'if_statement', 'children': ['99', '104', '148']},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': '=='},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'next_vertex'},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'current_cycle'},{'id': '103', 'type': 'integer', 'children': [], 'value': '0'},{'id': '104', 'type': 'block', 'children': ['105', '144']},{'id': '105', 'type': 'if_statement', 'children': ['106', '112']},{'id': '106', 'type': 'comparison_operator', 'children': ['107', '111'], 'value': '>'},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'current_cycle'},{'id': '111', 'type': 'integer', 'children': [], 'value': '1'},{'id': '112', 'type': 'block', 'children': ['113', '122', '137']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'pivot'},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'argmin'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'current_cycle'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'current_cycle'},{'id': '125', 'type': 'binary_operator', 'children': ['126', '131', '132'], 'value': '+'},{'id': '126', 'type': 'subscript', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'current_cycle'},{'id': '128', 'type': 'slice', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'pivot'},{'id': '130', 'type': 'colon', 'children': []},{'id': '131', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '132', 'type': 'subscript', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'current_cycle'},{'id': '134', 'type': 'slice', 'children': ['135', '136']},{'id': '135', 'type': 'colon', 'children': []},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'pivot'},{'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': 'closed_cycles'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'current_cycle'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'current_vertex'},{'id': '147', 'type': 'None', 'children': []},{'id': '148', 'type': 'else_clause', 'children': ['149']},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'current_vertex'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'next_vertex'},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'closed_cycles'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '159', 'type': 'argument_list', 'children': []},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'closed_cycles'},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '165', 'type': 'generator_expression', 'children': ['166', '170']},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'cycle'},{'id': '170', 'type': 'for_in_clause', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'cycle'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'closed_cycles'},{'id': '173', 'type': 'return_statement', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'closed_cycles'} | def get_closed_cycles(self):
closed_cycles = []
todo = set(self.forward.keys())
if todo != set(self.forward.values()):
raise GraphError("The subject and pattern graph must have the same "
"numbering.")
current_vertex = None
while len(todo) > 0:
if current_vertex == None:
current_vertex = todo.pop()
current_cycle = []
else:
todo.discard(current_vertex)
current_cycle.append(current_vertex)
next_vertex = self.get_destination(current_vertex)
if next_vertex == current_cycle[0]:
if len(current_cycle) > 1:
pivot = np.argmin(current_cycle)
current_cycle = current_cycle[pivot:] + \
current_cycle[:pivot]
closed_cycles.append(current_cycle)
current_vertex = None
else:
current_vertex = next_vertex
closed_cycles.sort()
closed_cycles = tuple(tuple(cycle) for cycle in closed_cycles)
return closed_cycles |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_exists'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '6', 'type': 'block', 'children': ['7', '15', '23', '34']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'bisect_left'},{'id': '12', 'type': 'argument_list', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'bisect_right'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': 'in'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '28', 'type': 'subscript', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '30', 'type': 'slice', 'children': ['31', '32', '33']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '32', 'type': 'colon', 'children': []},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '34', 'type': 'return_statement', 'children': ['35']},{'id': '35', 'type': 'expression_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'i'} | def sorted_exists(values, x):
i = bisect_left(values, x)
j = bisect_right(values, x)
exists = x in values[i:j]
return exists, i |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_index'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '6', 'type': 'block', 'children': ['7', '15', '23']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'bisect_left'},{'id': '12', 'type': 'argument_list', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'bisect_right'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '23', 'type': 'return_statement', 'children': ['24']},{'id': '24', 'type': 'binary_operator', 'children': ['25', '36'], 'value': '+'},{'id': '25', 'type': 'call', 'children': ['26', '34']},{'id': '26', 'type': 'attribute', 'children': ['27', '33']},{'id': '27', 'type': 'subscript', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '29', 'type': 'slice', 'children': ['30', '31', '32']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '31', 'type': 'colon', 'children': []},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'i'} | def sorted_index(values, x):
i = bisect_left(values, x)
j = bisect_right(values, x)
return values[i:j].index(x) + i |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_index'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '15', '45']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sorted_list_indexes'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': '_index'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': '_index'},{'id': '20', 'type': 'conditional_expression', 'children': ['21', '33', '36'], 'value': 'if'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'blist'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'list_comprehension', 'children': ['25', '30']},{'id': '25', 'type': 'subscript', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': '_index'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '30', 'type': 'for_in_clause', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_blist'},{'id': '36', 'type': 'list_comprehension', 'children': ['37', '42']},{'id': '37', 'type': 'subscript', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': '_index'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '42', 'type': 'for_in_clause', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': '_data'},{'id': '50', 'type': 'conditional_expression', 'children': ['51', '63', '66'], 'value': 'if'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'blist'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'list_comprehension', 'children': ['55', '60']},{'id': '55', 'type': 'subscript', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '58', 'type': 'identifier', 'children': [], 'value': '_data'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '60', 'type': 'for_in_clause', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '65', 'type': 'identifier', 'children': [], 'value': '_blist'},{'id': '66', 'type': 'list_comprehension', 'children': ['67', '72']},{'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': '_data'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '72', 'type': 'for_in_clause', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'sort'} | def sort_index(self):
sort = sorted_list_indexes(self._index)
self._index = blist([self._index[x] for x in sort]) if self._blist else [self._index[x] for x in sort]
self._data = blist([self._data[x] for x in sort]) if self._blist else [self._data[x] for x in sort] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_add_missing_rows'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '6', 'type': 'block', 'children': ['7', '21']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'new_indexes'},{'id': '10', 'type': 'list_comprehension', 'children': ['11', '12', '15']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '12', 'type': 'for_in_clause', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '15', 'type': 'if_clause', 'children': ['16']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'not'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_index'},{'id': '21', 'type': 'for_statement', 'children': ['22', '23', '24']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'new_indexes'},{'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': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_add_row'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'x'} | def _add_missing_rows(self, indexes):
new_indexes = [x for x in indexes if x not in self._index]
for x in new_indexes:
self._add_row(x) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_insert_missing_rows'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '6', 'type': 'block', 'children': ['7', '21']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'new_indexes'},{'id': '10', 'type': 'list_comprehension', 'children': ['11', '12', '15']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '12', 'type': 'for_in_clause', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '15', 'type': 'if_clause', 'children': ['16']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'not'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_index'},{'id': '21', 'type': 'for_statement', 'children': ['22', '23', '24']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'new_indexes'},{'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': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_insert_row'},{'id': '30', 'type': 'argument_list', 'children': ['31', '38']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'bisect_left'},{'id': '33', 'type': 'argument_list', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': '_index'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'x'} | def _insert_missing_rows(self, indexes):
new_indexes = [x for x in indexes if x not in self._index]
for x in new_indexes:
self._insert_row(bisect_left(self._index, x), x) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'append_row'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '7', 'type': 'block', 'children': ['8', '20', '29']},{'id': '8', 'type': 'if_statement', 'children': ['9', '14']},{'id': '9', 'type': 'comparison_operator', 'children': ['10', '11'], 'value': 'in'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': '_index'},{'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': 'IndexError'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'string', 'children': [], 'value': "'index already in Series'"},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'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': '_index'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '36']},{'id': '31', 'type': 'attribute', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': '_data'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'value'} | def append_row(self, index, value):
if index in self._index:
raise IndexError('index already in Series')
self._index.append(index)
self._data.append(value) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'append_rows'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '7', 'type': 'block', 'children': ['8', '24', '32', '51', '60']},{'id': '8', 'type': 'if_statement', 'children': ['9', '18']},{'id': '9', 'type': 'comparison_operator', 'children': ['10', '14'], 'value': '!='},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'raise_statement', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'string', 'children': [], 'value': "'length of values is not equal to length of indexes'"},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'combined_index'},{'id': '27', 'type': 'binary_operator', 'children': ['28', '31'], 'value': '+'},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': '_index'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '32', 'type': 'if_statement', 'children': ['33', '45']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '41'], 'value': '!='},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'combined_index'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'combined_index'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'raise_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'string', 'children': [], 'value': "'duplicate indexes in Series'"},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'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': '_index'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'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': '_data'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'values'} | def append_rows(self, indexes, values):
if len(values) != len(indexes):
raise ValueError('length of values is not equal to length of indexes')
combined_index = self._index + indexes
if len(set(combined_index)) != len(combined_index):
raise IndexError('duplicate indexes in Series')
self._index.extend(indexes)
self._data.extend(values) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort_columns'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'columns_list'},{'id': '6', 'type': 'block', 'children': ['7', '41', '56', '86']},{'id': '7', 'type': 'if_statement', 'children': ['8', '35']},{'id': '8', 'type': 'not_operator', 'children': ['9']},{'id': '9', 'type': '()', 'children': ['10']},{'id': '10', 'type': 'boolean_operator', 'children': ['11', '23'], 'value': 'and'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'list_comprehension', 'children': ['15', '18']},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'in'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'columns_list'},{'id': '18', 'type': 'for_in_clause', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': '_columns'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'list_comprehension', 'children': ['27', '32']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'in'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': '_columns'},{'id': '32', 'type': 'for_in_clause', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'columns_list'},{'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': 'ValueError'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'string', 'children': [], 'value': "'columns_list must be all in current columns, and all current columns must be in columns_list'"},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'new_sort'},{'id': '44', 'type': 'list_comprehension', 'children': ['45', '53']},{'id': '45', 'type': 'call', 'children': ['46', '51']},{'id': '46', 'type': 'attribute', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': '_columns'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '53', 'type': 'for_in_clause', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'columns_list'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': '_data'},{'id': '61', 'type': 'conditional_expression', 'children': ['62', '74', '77'], 'value': 'if'},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'blist'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'list_comprehension', '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': '_data'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '71', 'type': 'for_in_clause', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'new_sort'},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '76', 'type': 'identifier', 'children': [], 'value': '_blist'},{'id': '77', 'type': 'list_comprehension', 'children': ['78', '83']},{'id': '78', 'type': 'subscript', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '81', 'type': 'identifier', 'children': [], 'value': '_data'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '83', 'type': 'for_in_clause', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'new_sort'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '90', 'type': 'identifier', 'children': [], 'value': '_columns'},{'id': '91', 'type': 'conditional_expression', 'children': ['92', '104', '107', '108'], 'value': 'if'},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'blist'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'list_comprehension', 'children': ['96', '101']},{'id': '96', 'type': 'subscript', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': '_columns'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '101', 'type': 'for_in_clause', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'new_sort'},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '106', 'type': 'identifier', 'children': [], 'value': '_blist'},{'id': '107', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '108', 'type': 'list_comprehension', 'children': ['109', '114']},{'id': '109', 'type': 'subscript', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '112', 'type': 'identifier', 'children': [], 'value': '_columns'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '114', 'type': 'for_in_clause', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'new_sort'} | def _sort_columns(self, columns_list):
if not (all([x in columns_list for x in self._columns]) and all([x in self._columns for x in columns_list])):
raise ValueError(
'columns_list must be all in current columns, and all current columns must be in columns_list')
new_sort = [self._columns.index(x) for x in columns_list]
self._data = blist([self._data[x] for x in new_sort]) if self._blist else [self._data[x] for x in new_sort]
self._columns = blist([self._columns[x] for x in new_sort]) if self._blist \
else [self._columns[x] for x in new_sort] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'append_row'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'new_cols'},{'id': '9', 'type': 'True', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '23', '44', '53']},{'id': '11', 'type': 'if_statement', 'children': ['12', '17']},{'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'in'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': '_index'},{'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': 'IndexError'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'string', 'children': [], 'value': "'index already in DataFrame'"},{'id': '23', 'type': 'if_statement', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'new_cols'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'for_statement', 'children': ['27', '28', '29']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'if_statement', 'children': ['31', '36']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'not'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_columns'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': '_add_column'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '51']},{'id': '46', 'type': 'attribute', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': '_index'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '53', 'type': 'for_statement', 'children': ['54', '57', '63']},{'id': '54', 'type': 'pattern_list', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': '_columns'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '73']},{'id': '66', 'type': 'attribute', 'children': ['67', '72']},{'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': '_data'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '80', 'type': 'None', 'children': []} | def append_row(self, index, values, new_cols=True):
if index in self._index:
raise IndexError('index already in DataFrame')
if new_cols:
for col in values:
if col not in self._columns:
self._add_column(col)
self._index.append(index)
for c, col in enumerate(self._columns):
self._data[c].append(values.get(col, None)) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'append_rows'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'new_cols'},{'id': '9', 'type': 'True', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '35', '43', '62', '83', '92', '126']},{'id': '11', 'type': 'for_statement', 'children': ['12', '13', '14']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'if_statement', 'children': ['16', '27']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '23'], 'value': '>'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'subscript', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'raise_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'binary_operator', 'children': ['33', '34'], 'value': '%'},{'id': '33', 'type': 'string', 'children': [], 'value': "'length of %s column in values is longer than indexes'"},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'combined_index'},{'id': '38', 'type': 'binary_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': '_index'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '43', 'type': 'if_statement', 'children': ['44', '56']},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '52'], 'value': '!='},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'combined_index'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'combined_index'},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'raise_statement', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'string', 'children': [], 'value': "'duplicate indexes in DataFrames'"},{'id': '62', 'type': 'if_statement', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'new_cols'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'for_statement', 'children': ['66', '67', '68']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'if_statement', 'children': ['70', '75']},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': 'not'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '74', 'type': 'identifier', 'children': [], 'value': '_columns'},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '80', 'type': 'identifier', 'children': [], 'value': '_add_column'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'col'},{'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': '_index'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '92', 'type': 'for_statement', 'children': ['93', '96', '102']},{'id': '93', 'type': 'pattern_list', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '101', 'type': 'identifier', 'children': [], 'value': '_columns'},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '112']},{'id': '105', 'type': 'attribute', 'children': ['106', '111']},{'id': '106', 'type': 'subscript', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '109', 'type': 'identifier', 'children': [], 'value': '_data'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '117', 'type': 'argument_list', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '119', 'type': 'binary_operator', 'children': ['120', '122'], 'value': '*'},{'id': '120', 'type': 'list', 'children': ['121'], 'value': '[None]'},{'id': '121', 'type': 'None', 'children': []},{'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': 'indexes'},{'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': '_pad_data'},{'id': '131', 'type': 'argument_list', 'children': []} | def append_rows(self, indexes, values, new_cols=True):
for column in values:
if len(values[column]) > len(indexes):
raise ValueError('length of %s column in values is longer than indexes' % column)
combined_index = self._index + indexes
if len(set(combined_index)) != len(combined_index):
raise IndexError('duplicate indexes in DataFrames')
if new_cols:
for col in values:
if col not in self._columns:
self._add_column(col)
self._index.extend(indexes)
for c, col in enumerate(self._columns):
self._data[c].extend(values.get(col, [None] * len(indexes)))
self._pad_data() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_index'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '15', '45']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sorted_list_indexes'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': '_index'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': '_index'},{'id': '20', 'type': 'conditional_expression', 'children': ['21', '33', '36'], 'value': 'if'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'blist'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'list_comprehension', 'children': ['25', '30']},{'id': '25', 'type': 'subscript', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': '_index'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '30', 'type': 'for_in_clause', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_blist'},{'id': '36', 'type': 'list_comprehension', 'children': ['37', '42']},{'id': '37', 'type': 'subscript', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': '_index'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '42', 'type': 'for_in_clause', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '45', 'type': 'for_statement', 'children': ['46', '47', '56']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': '_data'},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '64']},{'id': '59', 'type': 'subscript', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': '_data'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '64', 'type': 'conditional_expression', 'children': ['65', '79', '82'], 'value': 'if'},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'blist'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'list_comprehension', 'children': ['69', '76']},{'id': '69', 'type': 'subscript', 'children': ['70', '75']},{'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': '_data'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '76', 'type': 'for_in_clause', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '81', 'type': 'identifier', 'children': [], 'value': '_blist'},{'id': '82', 'type': 'list_comprehension', 'children': ['83', '90']},{'id': '83', 'type': 'subscript', 'children': ['84', '89']},{'id': '84', 'type': 'subscript', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '87', 'type': 'identifier', 'children': [], 'value': '_data'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '90', 'type': 'for_in_clause', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'sort'} | def sort_index(self):
sort = sorted_list_indexes(self._index)
self._index = blist([self._index[x] for x in sort]) if self._blist else [self._index[x] for x in sort]
for c in range(len(self._data)):
self._data[c] = blist([self._data[c][i] for i in sort]) if self._blist else [self._data[c][i] for i in sort] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'tags'},{'id': '3', 'type': 'parameters', 'children': []},{'id': '4', 'type': 'block', 'children': ['5']},{'id': '5', 'type': 'return_statement', 'children': ['6']},{'id': '6', 'type': 'call', 'children': ['7', '27']},{'id': '7', 'type': 'attribute', 'children': ['8', '26']},{'id': '8', 'type': 'call', 'children': ['9', '25']},{'id': '9', 'type': 'attribute', 'children': ['10', '24']},{'id': '10', 'type': 'attribute', 'children': ['11', '23']},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'shell'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17', '20']},{'id': '16', 'type': 'string', 'children': [], 'value': "'git tag --sort=v:refname'"},{'id': '17', 'type': 'keyword_argument', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'capture'},{'id': '19', 'type': 'True', 'children': []},{'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'never_pretend'},{'id': '22', 'type': 'True', 'children': []},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '25', 'type': 'argument_list', 'children': []},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'splitlines'},{'id': '27', 'type': 'argument_list', 'children': []} | def tags():
return shell.run(
'git tag --sort=v:refname',
capture=True,
never_pretend=True
).stdout.strip().splitlines() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '90', '92']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'search'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '10', '15', '20', '25', '30', '35', '40', '45', '50', '55', '60', '65', '70', '75', '80', '85']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_default_parameter', 'children': ['6', '7', '9']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'typed_default_parameter', 'children': ['11', '12', '14']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '12', 'type': 'type', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '14', 'type': 'string', 'children': [], 'value': '""'},{'id': '15', 'type': 'typed_default_parameter', 'children': ['16', '17', '19']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'bbox'},{'id': '17', 'type': 'type', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'typed_default_parameter', 'children': ['21', '22', '24']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'poly'},{'id': '22', 'type': 'type', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'typed_default_parameter', 'children': ['26', '27', '29']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'georel'},{'id': '27', 'type': 'type', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '29', 'type': 'None', 'children': []},{'id': '30', 'type': 'typed_default_parameter', 'children': ['31', '32', '34']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '32', 'type': 'type', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '34', 'type': 'string', 'children': [], 'value': '"_created"'},{'id': '35', 'type': 'typed_default_parameter', 'children': ['36', '37', '39']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'order_dir'},{'id': '37', 'type': 'type', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '39', 'type': 'string', 'children': [], 'value': '"desc"'},{'id': '40', 'type': 'typed_default_parameter', 'children': ['41', '42', '44']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '42', 'type': 'type', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '44', 'type': 'integer', 'children': [], 'value': '100'},{'id': '45', 'type': 'typed_default_parameter', 'children': ['46', '47', '49']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '47', 'type': 'type', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '49', 'type': 'integer', 'children': [], 'value': '0'},{'id': '50', 'type': 'typed_default_parameter', 'children': ['51', '52', '54']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'share'},{'id': '52', 'type': 'type', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '54', 'type': 'None', 'children': []},{'id': '55', 'type': 'typed_default_parameter', 'children': ['56', '57', '59']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'specific_md'},{'id': '57', 'type': 'type', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '59', 'type': 'list', 'children': [], 'value': '[]'},{'id': '60', 'type': 'typed_default_parameter', 'children': ['61', '62', '64']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'include'},{'id': '62', 'type': 'type', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '64', 'type': 'list', 'children': [], 'value': '[]'},{'id': '65', 'type': 'typed_default_parameter', 'children': ['66', '67', '69']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'whole_share'},{'id': '67', 'type': 'type', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '69', 'type': 'True', 'children': []},{'id': '70', 'type': 'typed_default_parameter', 'children': ['71', '72', '74']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '72', 'type': 'type', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '74', 'type': 'True', 'children': []},{'id': '75', 'type': 'typed_default_parameter', 'children': ['76', '77', '79']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'augment'},{'id': '77', 'type': 'type', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '79', 'type': 'False', 'children': []},{'id': '80', 'type': 'typed_default_parameter', 'children': ['81', '82', '84']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'tags_as_dicts'},{'id': '82', 'type': 'type', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '84', 'type': 'False', 'children': []},{'id': '85', 'type': 'typed_default_parameter', 'children': ['86', '87', '89']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'prot'},{'id': '87', 'type': 'type', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '89', 'type': 'string', 'children': [], 'value': '"https"'},{'id': '90', 'type': 'type', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '92', 'type': 'block', 'children': ['93', '102', '111', '153', '166', '178', '222', '229', '237', '246', '341', '387', '467']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'specific_md'},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'checker'},{'id': '99', 'type': 'identifier', 'children': [], 'value': '_check_filter_specific_md'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'specific_md'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'include'},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'checker'},{'id': '108', 'type': 'identifier', 'children': [], 'value': '_check_filter_includes'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'include'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '114', 'type': 'dictionary', 'children': ['115', '118', '121', '126', '129', '132', '135', '138', '141', '144', '147', '150']},{'id': '115', 'type': 'pair', 'children': ['116', '117']},{'id': '116', 'type': 'string', 'children': [], 'value': '"_id"'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'specific_md'},{'id': '118', 'type': 'pair', 'children': ['119', '120']},{'id': '119', 'type': 'string', 'children': [], 'value': '"_include"'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'include'},{'id': '121', 'type': 'pair', 'children': ['122', '123']},{'id': '122', 'type': 'string', 'children': [], 'value': '"_lang"'},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'lang'},{'id': '126', 'type': 'pair', 'children': ['127', '128']},{'id': '127', 'type': 'string', 'children': [], 'value': '"_limit"'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '129', 'type': 'pair', 'children': ['130', '131']},{'id': '130', 'type': 'string', 'children': [], 'value': '"_offset"'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '132', 'type': 'pair', 'children': ['133', '134']},{'id': '133', 'type': 'string', 'children': [], 'value': '"box"'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'bbox'},{'id': '135', 'type': 'pair', 'children': ['136', '137']},{'id': '136', 'type': 'string', 'children': [], 'value': '"geo"'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'poly'},{'id': '138', 'type': 'pair', 'children': ['139', '140']},{'id': '139', 'type': 'string', 'children': [], 'value': '"rel"'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'georel'},{'id': '141', 'type': 'pair', 'children': ['142', '143']},{'id': '142', 'type': 'string', 'children': [], 'value': '"ob"'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '144', 'type': 'pair', 'children': ['145', '146']},{'id': '145', 'type': 'string', 'children': [], 'value': '"od"'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'order_dir'},{'id': '147', 'type': 'pair', 'children': ['148', '149']},{'id': '148', 'type': 'string', 'children': [], 'value': '"q"'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '150', 'type': 'pair', 'children': ['151', '152']},{'id': '151', 'type': 'string', 'children': [], 'value': '"s"'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'share'},{'id': '153', 'type': 'if_statement', 'children': ['154', '155', '163']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'check'},{'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': 'checker'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'check_request_parameters'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '163', 'type': 'else_clause', 'children': ['164']},{'id': '164', 'type': 'block', 'children': ['165']},{'id': '165', 'type': 'pass_statement', 'children': []},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'search_url'},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'string', 'children': [], 'value': '"{}://v1.{}.isogeo.com/resources/search"'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '173', 'type': 'argument_list', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'prot'},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'api_url'},{'id': '178', 'type': 'try_statement', 'children': ['179', '207']},{'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': 'search_req'},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '187', 'type': 'argument_list', 'children': ['188', '189', '194', '197', '202']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'search_url'},{'id': '189', 'type': 'keyword_argument', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '194', 'type': 'keyword_argument', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '197', 'type': 'keyword_argument', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'proxies'},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'proxies'},{'id': '202', 'type': 'keyword_argument', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'verify'},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'ssl'},{'id': '207', 'type': 'except_clause', 'children': ['208', '212']},{'id': '208', 'type': 'as_pattern', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '210', 'type': 'as_pattern_target', 'children': ['211']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '212', 'type': 'block', 'children': ['213', '220']},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '220', 'type': 'raise_statement', 'children': ['221']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'call', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'checker'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'check_api_response'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'search_req'},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'assignment', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'search_rez'},{'id': '232', 'type': 'call', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'search_req'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '236', 'type': 'argument_list', 'children': []},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'assignment', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'resources_count'},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'search_rez'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'string', 'children': [], 'value': '"total"'},{'id': '246', 'type': 'if_statement', 'children': ['247', '252', '338']},{'id': '247', 'type': 'boolean_operator', 'children': ['248', '251'], 'value': 'and'},{'id': '248', 'type': 'comparison_operator', 'children': ['249', '250'], 'value': '>'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'resources_count'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'whole_share'},{'id': '252', 'type': 'block', 'children': ['253', '257', '263', '332']},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'assignment', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'metadatas'},{'id': '256', 'type': 'list', 'children': [], 'value': '[]'},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'assignment', 'children': ['259', '262']},{'id': '259', 'type': 'subscript', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '261', 'type': 'string', 'children': [], 'value': '"_limit"'},{'id': '262', 'type': 'integer', 'children': [], 'value': '100'},{'id': '263', 'type': 'for_statement', 'children': ['264', '265', '280']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '265', 'type': 'call', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '267', 'type': 'argument_list', 'children': ['268', '269']},{'id': '268', 'type': 'integer', 'children': [], 'value': '0'},{'id': '269', 'type': 'binary_operator', 'children': ['270', '279'], 'value': '+'},{'id': '270', 'type': 'call', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '272', 'type': 'argument_list', 'children': ['273']},{'id': '273', 'type': 'call', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'ceil'},{'id': '275', 'type': 'argument_list', 'children': ['276']},{'id': '276', 'type': 'binary_operator', 'children': ['277', '278'], 'value': '/'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'resources_count'},{'id': '278', 'type': 'integer', 'children': [], 'value': '100'},{'id': '279', 'type': 'integer', 'children': [], 'value': '1'},{'id': '280', 'type': 'block', 'children': ['281', '289', '316']},{'id': '281', 'type': 'expression_statement', 'children': ['282']},{'id': '282', 'type': 'assignment', 'children': ['283', '286']},{'id': '283', 'type': 'subscript', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '285', 'type': 'string', 'children': [], 'value': '"_offset"'},{'id': '286', 'type': 'binary_operator', 'children': ['287', '288'], 'value': '*'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '288', 'type': 'integer', 'children': [], 'value': '100'},{'id': '289', 'type': 'expression_statement', 'children': ['290']},{'id': '290', 'type': 'assignment', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'search_req'},{'id': '292', 'type': 'call', 'children': ['293', '296']},{'id': '293', 'type': 'attribute', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '296', 'type': 'argument_list', 'children': ['297', '298', '303', '306', '311']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'search_url'},{'id': '298', 'type': 'keyword_argument', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '300', 'type': 'attribute', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '303', 'type': 'keyword_argument', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '306', 'type': 'keyword_argument', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'proxies'},{'id': '308', 'type': 'attribute', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'proxies'},{'id': '311', 'type': 'keyword_argument', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'verify'},{'id': '313', 'type': 'attribute', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'ssl'},{'id': '316', 'type': 'expression_statement', 'children': ['317']},{'id': '317', 'type': 'call', 'children': ['318', '321']},{'id': '318', 'type': 'attribute', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'metadatas'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '321', 'type': 'argument_list', 'children': ['322']},{'id': '322', 'type': 'call', 'children': ['323', '330']},{'id': '323', 'type': 'attribute', 'children': ['324', '329']},{'id': '324', 'type': 'call', 'children': ['325', '328']},{'id': '325', 'type': 'attribute', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'search_req'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '328', 'type': 'argument_list', 'children': []},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '330', 'type': 'argument_list', 'children': ['331']},{'id': '331', 'type': 'string', 'children': [], 'value': '"results"'},{'id': '332', 'type': 'expression_statement', 'children': ['333']},{'id': '333', 'type': 'assignment', 'children': ['334', '337']},{'id': '334', 'type': 'subscript', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'search_rez'},{'id': '336', 'type': 'string', 'children': [], 'value': '"results"'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'metadatas'},{'id': '338', 'type': 'else_clause', 'children': ['339']},{'id': '339', 'type': 'block', 'children': ['340']},{'id': '340', 'type': 'pass_statement', 'children': []},{'id': '341', 'type': 'if_statement', 'children': ['342', '343', '384']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'augment'},{'id': '343', 'type': 'block', 'children': ['344', '356']},{'id': '344', 'type': 'expression_statement', 'children': ['345']},{'id': '345', 'type': 'call', 'children': ['346', '349']},{'id': '346', 'type': 'attribute', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'add_tags_shares'},{'id': '349', 'type': 'argument_list', 'children': ['350']},{'id': '350', 'type': 'call', 'children': ['351', '354']},{'id': '351', 'type': 'attribute', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'search_rez'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '354', 'type': 'argument_list', 'children': ['355']},{'id': '355', 'type': 'string', 'children': [], 'value': '"tags"'},{'id': '356', 'type': 'if_statement', 'children': ['357', '358', '371']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'share'},{'id': '358', 'type': 'block', 'children': ['359']},{'id': '359', 'type': 'expression_statement', 'children': ['360']},{'id': '360', 'type': 'assignment', 'children': ['361', '369']},{'id': '361', 'type': 'subscript', 'children': ['362', '368']},{'id': '362', 'type': 'call', 'children': ['363', '366']},{'id': '363', 'type': 'attribute', 'children': ['364', '365']},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'search_rez'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '366', 'type': 'argument_list', 'children': ['367']},{'id': '367', 'type': 'string', 'children': [], 'value': '"query"'},{'id': '368', 'type': 'string', 'children': [], 'value': '"_shares"'},{'id': '369', 'type': 'list', 'children': ['370'], 'value': '[share]'},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'share'},{'id': '371', 'type': 'else_clause', 'children': ['372']},{'id': '372', 'type': 'block', 'children': ['373']},{'id': '373', 'type': 'expression_statement', 'children': ['374']},{'id': '374', 'type': 'assignment', 'children': ['375', '383']},{'id': '375', 'type': 'subscript', 'children': ['376', '382']},{'id': '376', 'type': 'call', 'children': ['377', '380']},{'id': '377', 'type': 'attribute', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'search_rez'},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '380', 'type': 'argument_list', 'children': ['381']},{'id': '381', 'type': 'string', 'children': [], 'value': '"query"'},{'id': '382', 'type': 'string', 'children': [], 'value': '"_shares"'},{'id': '383', 'type': 'list', 'children': [], 'value': '[]'},{'id': '384', 'type': 'else_clause', 'children': ['385']},{'id': '385', 'type': 'block', 'children': ['386']},{'id': '386', 'type': 'pass_statement', 'children': []},{'id': '387', 'type': 'if_statement', 'children': ['388', '389', '464']},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'tags_as_dicts'},{'id': '389', 'type': 'block', 'children': ['390', '414', '425', '436', '450']},{'id': '390', 'type': 'expression_statement', 'children': ['391']},{'id': '391', 'type': 'assignment', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'new_tags'},{'id': '393', 'type': 'call', 'children': ['394', '397']},{'id': '394', 'type': 'attribute', 'children': ['395', '396']},{'id': '395', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'tags_to_dict'},{'id': '397', 'type': 'argument_list', 'children': ['398', '406']},{'id': '398', 'type': 'keyword_argument', 'children': ['399', '400']},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '400', 'type': 'call', 'children': ['401', '404']},{'id': '401', 'type': 'attribute', 'children': ['402', '403']},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'search_rez'},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '404', 'type': 'argument_list', 'children': ['405']},{'id': '405', 'type': 'string', 'children': [], 'value': '"tags"'},{'id': '406', 'type': 'keyword_argument', 'children': ['407', '408']},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'prev_query'},{'id': '408', 'type': 'call', 'children': ['409', '412']},{'id': '409', 'type': 'attribute', 'children': ['410', '411']},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'search_rez'},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '412', 'type': 'argument_list', 'children': ['413']},{'id': '413', 'type': 'string', 'children': [], 'value': '"query"'},{'id': '414', 'type': 'expression_statement', 'children': ['415']},{'id': '415', 'type': 'call', 'children': ['416', '424']},{'id': '416', 'type': 'attribute', 'children': ['417', '423']},{'id': '417', 'type': 'call', 'children': ['418', '421']},{'id': '418', 'type': 'attribute', 'children': ['419', '420']},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'search_rez'},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '421', 'type': 'argument_list', 'children': ['422']},{'id': '422', 'type': 'string', 'children': [], 'value': '"tags"'},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'clear'},{'id': '424', 'type': 'argument_list', 'children': []},{'id': '425', 'type': 'expression_statement', 'children': ['426']},{'id': '426', 'type': 'call', 'children': ['427', '435']},{'id': '427', 'type': 'attribute', 'children': ['428', '434']},{'id': '428', 'type': 'call', 'children': ['429', '432']},{'id': '429', 'type': 'attribute', 'children': ['430', '431']},{'id': '430', 'type': 'identifier', 'children': [], 'value': 'search_rez'},{'id': '431', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '432', 'type': 'argument_list', 'children': ['433']},{'id': '433', 'type': 'string', 'children': [], 'value': '"query"'},{'id': '434', 'type': 'identifier', 'children': [], 'value': 'clear'},{'id': '435', 'type': 'argument_list', 'children': []},{'id': '436', 'type': 'expression_statement', 'children': ['437']},{'id': '437', 'type': 'call', 'children': ['438', '446']},{'id': '438', 'type': 'attribute', 'children': ['439', '445']},{'id': '439', 'type': 'call', 'children': ['440', '443']},{'id': '440', 'type': 'attribute', 'children': ['441', '442']},{'id': '441', 'type': 'identifier', 'children': [], 'value': 'search_rez'},{'id': '442', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '443', 'type': 'argument_list', 'children': ['444']},{'id': '444', 'type': 'string', 'children': [], 'value': '"tags"'},{'id': '445', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '446', 'type': 'argument_list', 'children': ['447']},{'id': '447', 'type': 'subscript', 'children': ['448', '449']},{'id': '448', 'type': 'identifier', 'children': [], 'value': 'new_tags'},{'id': '449', 'type': 'integer', 'children': [], 'value': '0'},{'id': '450', 'type': 'expression_statement', 'children': ['451']},{'id': '451', 'type': 'call', 'children': ['452', '460']},{'id': '452', 'type': 'attribute', 'children': ['453', '459']},{'id': '453', 'type': 'call', 'children': ['454', '457']},{'id': '454', 'type': 'attribute', 'children': ['455', '456']},{'id': '455', 'type': 'identifier', 'children': [], 'value': 'search_rez'},{'id': '456', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '457', 'type': 'argument_list', 'children': ['458']},{'id': '458', 'type': 'string', 'children': [], 'value': '"query"'},{'id': '459', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '460', 'type': 'argument_list', 'children': ['461']},{'id': '461', 'type': 'subscript', 'children': ['462', '463']},{'id': '462', 'type': 'identifier', 'children': [], 'value': 'new_tags'},{'id': '463', 'type': 'integer', 'children': [], 'value': '1'},{'id': '464', 'type': 'else_clause', 'children': ['465']},{'id': '465', 'type': 'block', 'children': ['466']},{'id': '466', 'type': 'pass_statement', 'children': []},{'id': '467', 'type': 'return_statement', 'children': ['468']},{'id': '468', 'type': 'identifier', 'children': [], 'value': 'search_rez'} | def search(
self,
token: dict = None,
query: str = "",
bbox: list = None,
poly: str = None,
georel: str = None,
order_by: str = "_created",
order_dir: str = "desc",
page_size: int = 100,
offset: int = 0,
share: str = None,
specific_md: list = [],
include: list = [],
whole_share: bool = True,
check: bool = True,
augment: bool = False,
tags_as_dicts: bool = False,
prot: str = "https",
) -> dict:
specific_md = checker._check_filter_specific_md(specific_md)
include = checker._check_filter_includes(include)
payload = {
"_id": specific_md,
"_include": include,
"_lang": self.lang,
"_limit": page_size,
"_offset": offset,
"box": bbox,
"geo": poly,
"rel": georel,
"ob": order_by,
"od": order_dir,
"q": query,
"s": share,
}
if check:
checker.check_request_parameters(payload)
else:
pass
search_url = "{}://v1.{}.isogeo.com/resources/search".format(prot, self.api_url)
try:
search_req = self.get(
search_url,
headers=self.header,
params=payload,
proxies=self.proxies,
verify=self.ssl,
)
except Exception as e:
logging.error(e)
raise Exception
checker.check_api_response(search_req)
search_rez = search_req.json()
resources_count = search_rez.get("total")
if resources_count > page_size and whole_share:
metadatas = []
payload["_limit"] = 100
for idx in range(0, int(ceil(resources_count / 100)) + 1):
payload["_offset"] = idx * 100
search_req = self.get(
search_url,
headers=self.header,
params=payload,
proxies=self.proxies,
verify=self.ssl,
)
metadatas.extend(search_req.json().get("results"))
search_rez["results"] = metadatas
else:
pass
if augment:
self.add_tags_shares(search_rez.get("tags"))
if share:
search_rez.get("query")["_shares"] = [share]
else:
search_rez.get("query")["_shares"] = []
else:
pass
if tags_as_dicts:
new_tags = utils.tags_to_dict(
tags=search_rez.get("tags"), prev_query=search_rez.get("query")
)
search_rez.get("tags").clear()
search_rez.get("query").clear()
search_rez.get("tags").update(new_tags[0])
search_rez.get("query").update(new_tags[1])
else:
pass
return search_rez |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '60', '62']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'keywords'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '10', '15', '20', '25', '30', '35', '40', '45', '50', '55']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_default_parameter', 'children': ['6', '7', '9']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'typed_default_parameter', 'children': ['11', '12', '14']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'thez_id'},{'id': '12', 'type': 'type', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '14', 'type': 'string', 'children': [], 'value': '"1616597fbc4348c8b11ef9d59cf594c8"'},{'id': '15', 'type': 'typed_default_parameter', 'children': ['16', '17', '19']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '17', 'type': 'type', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '19', 'type': 'string', 'children': [], 'value': '""'},{'id': '20', 'type': 'typed_default_parameter', 'children': ['21', '22', '24']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '22', 'type': 'type', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '24', 'type': 'integer', 'children': [], 'value': '0'},{'id': '25', 'type': 'typed_default_parameter', 'children': ['26', '27', '29']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '27', 'type': 'type', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '29', 'type': 'string', 'children': [], 'value': '"text"'},{'id': '30', 'type': 'typed_default_parameter', 'children': ['31', '32', '34']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'order_dir'},{'id': '32', 'type': 'type', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '34', 'type': 'string', 'children': [], 'value': '"desc"'},{'id': '35', 'type': 'typed_default_parameter', 'children': ['36', '37', '39']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '37', 'type': 'type', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '39', 'type': 'integer', 'children': [], 'value': '20'},{'id': '40', 'type': 'typed_default_parameter', 'children': ['41', '42', '44']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'specific_md'},{'id': '42', 'type': 'type', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '44', 'type': 'list', 'children': [], 'value': '[]'},{'id': '45', 'type': 'typed_default_parameter', 'children': ['46', '47', '49']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'specific_tag'},{'id': '47', 'type': 'type', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '49', 'type': 'list', 'children': [], 'value': '[]'},{'id': '50', 'type': 'typed_default_parameter', 'children': ['51', '52', '54']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'include'},{'id': '52', 'type': 'type', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '54', 'type': 'list', 'children': [], 'value': '[]'},{'id': '55', 'type': 'typed_default_parameter', 'children': ['56', '57', '59']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'prot'},{'id': '57', 'type': 'type', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '59', 'type': 'string', 'children': [], 'value': '"https"'},{'id': '60', 'type': 'type', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '62', 'type': 'block', 'children': ['63', '72', '82', '91', '122', '135', '162', '169']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'specific_md'},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'checker'},{'id': '69', 'type': 'identifier', 'children': [], 'value': '_check_filter_specific_md'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'specific_md'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'include'},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'checker'},{'id': '78', 'type': 'identifier', 'children': [], 'value': '_check_filter_includes'},{'id': '79', 'type': 'argument_list', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'include'},{'id': '81', 'type': 'string', 'children': [], 'value': '"keyword"'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'specific_tag'},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'checker'},{'id': '88', 'type': 'identifier', 'children': [], 'value': '_check_filter_specific_tag'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'specific_tag'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '94', 'type': 'dictionary', 'children': ['95', '98', '101', '104', '107', '110', '113', '116', '119']},{'id': '95', 'type': 'pair', 'children': ['96', '97']},{'id': '96', 'type': 'string', 'children': [], 'value': '"_id"'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'specific_md'},{'id': '98', 'type': 'pair', 'children': ['99', '100']},{'id': '99', 'type': 'string', 'children': [], 'value': '"_include"'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'include'},{'id': '101', 'type': 'pair', 'children': ['102', '103']},{'id': '102', 'type': 'string', 'children': [], 'value': '"_limit"'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '104', 'type': 'pair', 'children': ['105', '106']},{'id': '105', 'type': 'string', 'children': [], 'value': '"_offset"'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '107', 'type': 'pair', 'children': ['108', '109']},{'id': '108', 'type': 'string', 'children': [], 'value': '"_tag"'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'specific_tag'},{'id': '110', 'type': 'pair', 'children': ['111', '112']},{'id': '111', 'type': 'string', 'children': [], 'value': '"tid"'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'thez_id'},{'id': '113', 'type': 'pair', 'children': ['114', '115']},{'id': '114', 'type': 'string', 'children': [], 'value': '"ob"'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '116', 'type': 'pair', 'children': ['117', '118']},{'id': '117', 'type': 'string', 'children': [], 'value': '"od"'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'order_dir'},{'id': '119', 'type': 'pair', 'children': ['120', '121']},{'id': '120', 'type': 'string', 'children': [], 'value': '"q"'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'keywords_url'},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'string', 'children': [], 'value': '"{}://v1.{}.isogeo.com/thesauri/{}/keywords/search"'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '129', 'type': 'argument_list', 'children': ['130', '131', '134']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'prot'},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'api_url'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'thez_id'},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'kwds_req'},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '142', 'type': 'argument_list', 'children': ['143', '144', '149', '152', '157']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'keywords_url'},{'id': '144', 'type': 'keyword_argument', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '149', 'type': 'keyword_argument', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'proxies'},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'proxies'},{'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'verify'},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'ssl'},{'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': 'checker'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'check_api_response'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'kwds_req'},{'id': '169', 'type': 'return_statement', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'kwds_req'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '174', 'type': 'argument_list', 'children': []} | def keywords(
self,
token: dict = None,
thez_id: str = "1616597fbc4348c8b11ef9d59cf594c8",
query: str = "",
offset: int = 0,
order_by: str = "text",
order_dir: str = "desc",
page_size: int = 20,
specific_md: list = [],
specific_tag: list = [],
include: list = [],
prot: str = "https",
) -> dict:
specific_md = checker._check_filter_specific_md(specific_md)
include = checker._check_filter_includes(include, "keyword")
specific_tag = checker._check_filter_specific_tag(specific_tag)
payload = {
"_id": specific_md,
"_include": include,
"_limit": page_size,
"_offset": offset,
"_tag": specific_tag,
"tid": thez_id,
"ob": order_by,
"od": order_dir,
"q": query,
}
keywords_url = "{}://v1.{}.isogeo.com/thesauri/{}/keywords/search".format(
prot, self.api_url, thez_id
)
kwds_req = self.get(
keywords_url,
headers=self.header,
params=payload,
proxies=self.proxies,
verify=self.ssl,
)
checker.check_api_response(kwds_req)
return kwds_req.json() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_field_sort_name'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '6', 'type': 'block', 'children': ['7', '51']},{'id': '7', 'type': 'if_statement', 'children': ['8', '17']},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '10', 'type': 'argument_list', 'children': ['11', '16']},{'id': '11', 'type': 'subscript', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '14', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'DateItemField'},{'id': '17', 'type': 'block', 'children': ['18', '29', '40']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27', '28']},{'id': '26', 'type': 'string', 'children': [], 'value': "'year'"},{'id': '27', 'type': 'string', 'children': [], 'value': "'date0'"},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38', '39']},{'id': '37', 'type': 'string', 'children': [], 'value': "'month'"},{'id': '38', 'type': 'string', 'children': [], 'value': "'date1'"},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'name'},{'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': 'string', 'children': [], 'value': "'day'"},{'id': '49', 'type': 'string', 'children': [], 'value': "'date2'"},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '51', 'type': 'return_statement', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'name'} | def _field_sort_name(cls, name):
if isinstance(cls.__dict__[name], DateItemField):
name = re.sub('year', 'date0', name)
name = re.sub('month', 'date1', name)
name = re.sub('day', 'date2', name)
return name |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_fields'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'for_statement', 'children': ['7', '8', '21']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'property'},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '10', 'type': 'argument_list', 'children': ['11', '16']},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_field_sort_name'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'yield', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'property'} | def sorted_fields(cls):
for property in sorted(cls.fields(), key=cls._field_sort_name):
yield property |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'set_vassals_wrapper_params'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'wrapper'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'overrides'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'fallbacks'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '23', '34', '45']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': '_set'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'string', 'children': [], 'value': "'emperor-wrapper'"},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'wrapper'},{'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': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_set'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30', '31']},{'id': '29', 'type': 'string', 'children': [], 'value': "'emperor-wrapper-override'"},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'overrides'},{'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'multi'},{'id': '33', 'type': 'True', 'children': []},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': '_set'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41', '42']},{'id': '40', 'type': 'string', 'children': [], 'value': "'emperor-wrapper-fallback'"},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'fallbacks'},{'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'multi'},{'id': '44', 'type': 'True', 'children': []},{'id': '45', 'type': 'return_statement', 'children': ['46']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': '_section'} | def set_vassals_wrapper_params(self, wrapper=None, overrides=None, fallbacks=None):
self._set('emperor-wrapper', wrapper)
self._set('emperor-wrapper-override', overrides, multi=True)
self._set('emperor-wrapper-fallback', fallbacks, multi=True)
return self._section |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_query_parameters_to_url'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'query_parameters'},{'id': '6', 'type': 'block', 'children': ['7', '18', '31', '38', '44', '63', '75']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'url_parts'},{'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': 'urllib'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'parse'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'urlparse'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'qs_args'},{'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': 'urllib'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'parse'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'parse_qs'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'subscript', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'url_parts'},{'id': '30', 'type': 'integer', 'children': [], 'value': '4'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'qs_args'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'query_parameters'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'sorted_qs_args'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '43', 'type': 'argument_list', 'children': []},{'id': '44', 'type': 'for_statement', 'children': ['45', '46', '54']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'qs_args'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '53', 'type': 'argument_list', 'children': []},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '60']},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'sorted_qs_args'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '60', 'type': 'subscript', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'qs_args'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'new_qs'},{'id': '66', 'type': 'call', 'children': ['67', '72']},{'id': '67', 'type': 'attribute', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'urllib'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'parse'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'urlencode'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'sorted_qs_args'},{'id': '74', 'type': 'True', 'children': []},{'id': '75', 'type': 'return_statement', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '82']},{'id': '77', 'type': 'attribute', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'urllib'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'parse'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'urlunparse'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'binary_operator', 'children': ['84', '96'], 'value': '+'},{'id': '84', 'type': 'binary_operator', 'children': ['85', '94'], 'value': '+'},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'url_parts'},{'id': '90', 'type': 'slice', 'children': ['91', '92', '93']},{'id': '91', 'type': 'integer', 'children': [], 'value': '0'},{'id': '92', 'type': 'colon', 'children': []},{'id': '93', 'type': 'integer', 'children': [], 'value': '4'},{'id': '94', 'type': 'list', 'children': ['95'], 'value': '[new_qs]'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'new_qs'},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'subscript', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'url_parts'},{'id': '101', 'type': 'slice', 'children': ['102', '103']},{'id': '102', 'type': 'integer', 'children': [], 'value': '5'},{'id': '103', 'type': 'colon', 'children': []} | def add_query_parameters_to_url(url, query_parameters):
url_parts = urllib.parse.urlparse(url)
qs_args = urllib.parse.parse_qs(url_parts[4])
qs_args.update(query_parameters)
sorted_qs_args = OrderedDict()
for k in sorted(qs_args.keys()):
sorted_qs_args[k] = qs_args[k]
new_qs = urllib.parse.urlencode(sorted_qs_args, True)
return urllib.parse.urlunparse(list(url_parts[0:4]) + [new_qs] + list(url_parts[5:])) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'elements'},{'id': '6', 'type': 'block', 'children': ['7', '9', '14', '22', '48']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'string', 'children': [], 'value': "''' Merges all scraping results to a list sorted by frequency of occurrence. '''"},{'id': '9', 'type': 'import_from_statement', 'children': ['10', '12']},{'id': '10', 'type': 'dotted_name', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '12', 'type': 'dotted_name', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'Counter'},{'id': '14', 'type': 'import_from_statement', 'children': ['15', '18', '20']},{'id': '15', 'type': 'dotted_name', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'lltk'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '18', 'type': 'dotted_name', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'list2tuple'},{'id': '20', 'type': 'dotted_name', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'tuple2list'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'merged'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'tuple2list'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'list_comprehension', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '30', 'type': 'for_in_clause', 'children': ['31', '34']},{'id': '31', 'type': 'pattern_list', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '34', 'type': 'call', 'children': ['35', '47']},{'id': '35', 'type': 'attribute', 'children': ['36', '46']},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'Counter'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'list2tuple'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'elements'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'most_common'},{'id': '47', 'type': 'argument_list', 'children': []},{'id': '48', 'type': 'return_statement', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'merged'} | def merge(self, elements):
''' Merges all scraping results to a list sorted by frequency of occurrence. '''
from collections import Counter
from lltk.utils import list2tuple, tuple2list
merged = tuple2list([value for value, count in Counter(list2tuple(list(elements))).most_common()])
return merged |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'in1d_sorted'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'ar1'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'ar2'},{'id': '6', 'type': 'block', 'children': ['7', '26', '35', '46']},{'id': '7', 'type': 'if_statement', 'children': ['8', '23']},{'id': '8', 'type': 'boolean_operator', 'children': ['9', '16'], 'value': 'or'},{'id': '9', 'type': 'comparison_operator', 'children': ['10', '15'], 'value': '=='},{'id': '10', 'type': 'subscript', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'ar1'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '14', 'type': 'integer', 'children': [], 'value': '0'},{'id': '15', 'type': 'integer', 'children': [], 'value': '0'},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '22'], 'value': '=='},{'id': '17', 'type': 'subscript', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'ar2'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '21', 'type': 'integer', 'children': [], 'value': '0'},{'id': '22', 'type': 'integer', 'children': [], 'value': '0'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'list', 'children': [], 'value': '[]'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'inds'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'ar2'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'searchsorted'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'ar1'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '45']},{'id': '37', 'type': 'subscript', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'inds'},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': '=='},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'inds'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'ar2'},{'id': '45', 'type': 'integer', 'children': [], 'value': '0'},{'id': '46', 'type': 'return_statement', 'children': ['47']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '51'], 'value': '=='},{'id': '48', 'type': 'subscript', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'ar2'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'inds'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'ar1'} | def in1d_sorted(ar1, ar2):
if ar1.shape[0] == 0 or ar2.shape[0] == 0:
return []
inds = ar2.searchsorted(ar1)
inds[inds == len(ar2)] = 0
return ar2[inds] == ar1 |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_parameter_value_from_file_names'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '13', 'type': 'True', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '39', '47', '54', '66', '75', '83', '87', '193']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'binary_operator', 'children': ['22', '38'], 'value': '+'},{'id': '22', 'type': 'binary_operator', 'children': ['23', '31'], 'value': '+'},{'id': '23', 'type': 'binary_operator', 'children': ['24', '30'], 'value': '+'},{'id': '24', 'type': 'binary_operator', 'children': ['25', '26'], 'value': '+'},{'id': '25', 'type': 'string', 'children': [], 'value': "'Get the parameter: '"},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '30', 'type': 'string', 'children': [], 'value': "' values from the file names of '"},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '38', 'type': 'string', 'children': [], 'value': "' files'"},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'files_dict'},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '46', 'type': 'argument_list', 'children': []},{'id': '47', 'type': 'if_statement', 'children': ['48', '51']},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': 'is'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '50', 'type': 'None', 'children': []},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'return_statement', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'files_dict'},{'id': '54', 'type': 'if_statement', 'children': ['55', '60']},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '64', 'type': 'tuple', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'search_string'},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '75', 'type': 'for_statement', 'children': ['76', '77', '78']},{'id': '76', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'augmented_assignment', 'children': ['81', '82'], 'value': '+='},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'search_string'},{'id': '82', 'type': 'string', 'children': [], 'value': "r'_(-?\\d+)'"},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '86', 'type': 'dictionary', 'children': []},{'id': '87', 'type': 'for_statement', 'children': ['88', '89', '90']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'one_file'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '90', 'type': 'block', 'children': ['91', '101']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'parameter_values'},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '98', 'type': 'argument_list', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'search_string'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'one_file'},{'id': '101', 'type': 'if_statement', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'parameter_values'},{'id': '103', 'type': 'block', 'children': ['104', '130', '142', '155']},{'id': '104', 'type': 'if_statement', 'children': ['105', '112']},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '107', 'type': 'argument_list', 'children': ['108', '111']},{'id': '108', 'type': 'subscript', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'parameter_values'},{'id': '110', 'type': 'integer', 'children': [], 'value': '0'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'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': 'parameter_values'},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'reduce'},{'id': '121', 'type': 'argument_list', 'children': ['122', '129']},{'id': '122', 'type': 'lambda', 'children': ['123', '126']},{'id': '123', 'type': 'lambda_parameters', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 't1'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 't2'},{'id': '126', 'type': 'binary_operator', 'children': ['127', '128'], 'value': '+'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 't1'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 't2'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'parameter_values'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'parameter_values'},{'id': '133', 'type': 'list_comprehension', 'children': ['134', '139']},{'id': '134', 'type': 'list', 'children': ['135'], 'value': '[int(i), ]'},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '139', 'type': 'for_in_clause', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'parameter_values'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '147']},{'id': '144', 'type': 'subscript', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'files_dict'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'one_file'},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '152', 'type': 'argument_list', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'parameter_values'},{'id': '155', 'type': 'if_statement', 'children': ['156', '157', '183']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '157', 'type': 'block', 'children': ['158']},{'id': '158', 'type': 'for_statement', 'children': ['159', '162', '167']},{'id': '159', 'type': 'pattern_list', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'files_dict'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '166', 'type': 'argument_list', 'children': []},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'if_statement', 'children': ['169', '176']},{'id': '169', 'type': 'comparison_operator', 'children': ['170', '171'], 'value': 'not'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '175', 'type': 'argument_list', 'children': []},{'id': '176', 'type': 'block', 'children': ['177']},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '182']},{'id': '179', 'type': 'subscript', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '183', 'type': 'else_clause', 'children': ['184']},{'id': '184', 'type': 'block', 'children': ['185']},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '190']},{'id': '187', 'type': 'subscript', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'one_file'},{'id': '190', 'type': 'subscript', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'files_dict'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'one_file'},{'id': '193', 'type': 'return_statement', 'children': ['194']},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'conditional_expression', 'children': ['200', '214', '215'], 'value': 'if'},{'id': '200', 'type': 'call', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '202', 'type': 'argument_list', 'children': ['203', '208']},{'id': '203', 'type': 'call', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '207', 'type': 'argument_list', 'children': []},{'id': '208', 'type': 'keyword_argument', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'itemgetter'},{'id': '212', 'type': 'argument_list', 'children': ['213']},{'id': '213', 'type': 'integer', 'children': [], 'value': '1'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'files_dict'} | def get_parameter_value_from_file_names(files, parameters=None, unique=False, sort=True):
logging.debug('Get the parameter: ' + str(parameters) + ' values from the file names of ' + str(len(files)) + ' files')
files_dict = collections.OrderedDict()
if parameters is None:
return files_dict
if isinstance(parameters, basestring):
parameters = (parameters, )
search_string = '_'.join(parameters)
for _ in parameters:
search_string += r'_(-?\d+)'
result = {}
for one_file in files:
parameter_values = re.findall(search_string, one_file)
if parameter_values:
if isinstance(parameter_values[0], tuple):
parameter_values = list(reduce(lambda t1, t2: t1 + t2, parameter_values))
parameter_values = [[int(i), ] for i in parameter_values]
files_dict[one_file] = dict(zip(parameters, parameter_values))
if unique:
for key, value in files_dict.items():
if value not in result.values():
result[key] = value
else:
result[one_file] = files_dict[one_file]
return collections.OrderedDict(sorted(result.iteritems(), key=itemgetter(1)) if sort else files_dict) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_data_file_names_from_scan_base'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '13', '16']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'scan_base'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'filter_str'},{'id': '7', 'type': 'list', 'children': ['8', '9', '10', '11', '12'], 'value': "['_analyzed.h5', '_interpreted.h5', '_cut.h5', '_result.h5', '_hists.h5']"},{'id': '8', 'type': 'string', 'children': [], 'value': "'_analyzed.h5'"},{'id': '9', 'type': 'string', 'children': [], 'value': "'_interpreted.h5'"},{'id': '10', 'type': 'string', 'children': [], 'value': "'_cut.h5'"},{'id': '11', 'type': 'string', 'children': [], 'value': "'_result.h5'"},{'id': '12', 'type': 'string', 'children': [], 'value': "'_hists.h5'"},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'sort_by_time'},{'id': '15', 'type': 'True', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'meta_data_v2'},{'id': '18', 'type': 'True', 'children': []},{'id': '19', 'type': 'block', 'children': ['20', '24', '31', '43', '84', '124', '249']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'data_files'},{'id': '23', 'type': 'list', 'children': [], 'value': '[]'},{'id': '24', 'type': 'if_statement', 'children': ['25', '28']},{'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'is'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'scan_base'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'return_statement', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'data_files'},{'id': '31', 'type': 'if_statement', 'children': ['32', '37']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'scan_base'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'scan_base'},{'id': '41', 'type': 'list', 'children': ['42'], 'value': '[scan_base]'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'scan_base'},{'id': '43', 'type': 'for_statement', 'children': ['44', '45', '46']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'scan_base_str'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'scan_base'},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'if_statement', 'children': ['48', '60', '68']},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': '=='},{'id': '49', 'type': 'string', 'children': [], 'value': "'.h5'"},{'id': '50', 'type': 'subscript', 'children': ['51', '59']},{'id': '51', 'type': 'call', 'children': ['52', '57']},{'id': '52', 'type': 'attribute', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'splitext'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'scan_base_str'},{'id': '59', 'type': 'integer', 'children': [], 'value': '1'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'data_files'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'scan_base_str'},{'id': '68', 'type': 'else_clause', 'children': ['69']},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'data_files'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'extend'},{'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': 'glob'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'glob'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'binary_operator', 'children': ['82', '83'], 'value': '+'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'scan_base_str'},{'id': '83', 'type': 'string', 'children': [], 'value': "'*.h5'"},{'id': '84', 'type': 'if_statement', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'filter_str'},{'id': '86', 'type': 'block', 'children': ['87', '99']},{'id': '87', 'type': 'if_statement', 'children': ['88', '93']},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'filter_str'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'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': 'filter_str'},{'id': '97', 'type': 'list', 'children': ['98'], 'value': '[filter_str]'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'filter_str'},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'data_files'},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '104', 'type': 'argument_list', 'children': ['105', '123']},{'id': '105', 'type': 'lambda', 'children': ['106', '108']},{'id': '106', 'type': 'lambda_parameters', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'data_file'},{'id': '108', 'type': 'not_operator', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'list_comprehension', 'children': ['113', '120']},{'id': '113', 'type': '()', 'children': ['114']},{'id': '114', 'type': 'conditional_expression', 'children': ['115', '116', '119'], 'value': 'if'},{'id': '115', 'type': 'True', 'children': []},{'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': 'in'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'data_file'},{'id': '119', 'type': 'False', 'children': []},{'id': '120', 'type': 'for_in_clause', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'filter_str'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'data_files'},{'id': '124', 'type': 'if_statement', 'children': ['125', '133']},{'id': '125', 'type': 'boolean_operator', 'children': ['126', '127'], 'value': 'and'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'sort_by_time'},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '132'], 'value': '>'},{'id': '128', 'type': 'call', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'data_files'},{'id': '132', 'type': 'integer', 'children': [], 'value': '1'},{'id': '133', 'type': 'block', 'children': ['134', '138', '231']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'f_list'},{'id': '137', 'type': 'dictionary', 'children': []},{'id': '138', 'type': 'for_statement', 'children': ['139', '140', '141']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'data_file'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'data_files'},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'with_statement', 'children': ['143', '157']},{'id': '143', 'type': 'with_clause', 'children': ['144']},{'id': '144', 'type': 'with_item', 'children': ['145']},{'id': '145', 'type': 'as_pattern', 'children': ['146', '155']},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'tb'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'open_file'},{'id': '150', 'type': 'argument_list', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'data_file'},{'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '154', 'type': 'string', 'children': [], 'value': '"r"'},{'id': '155', 'type': 'as_pattern_target', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'h5_file'},{'id': '157', 'type': 'block', 'children': ['158']},{'id': '158', 'type': 'try_statement', 'children': ['159', '168', '184']},{'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': 'meta_data'},{'id': '163', 'type': 'attribute', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'h5_file'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'meta_data'},{'id': '168', 'type': 'except_clause', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'tb'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'NoSuchNodeError'},{'id': '172', 'type': 'block', 'children': ['173']},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'call', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'binary_operator', 'children': ['180', '181'], 'value': '%'},{'id': '180', 'type': 'string', 'children': [], 'value': '"File %s is missing meta_data"'},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'h5_file'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '184', 'type': 'else_clause', 'children': ['185']},{'id': '185', 'type': 'block', 'children': ['186']},{'id': '186', 'type': 'try_statement', 'children': ['187', '209', '223']},{'id': '187', 'type': 'block', 'children': ['188']},{'id': '188', 'type': 'if_statement', 'children': ['189', '190', '199']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'meta_data_v2'},{'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': 'timestamp'},{'id': '194', 'type': 'subscript', 'children': ['195', '198']},{'id': '195', 'type': 'subscript', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'meta_data'},{'id': '197', 'type': 'integer', 'children': [], 'value': '0'},{'id': '198', 'type': 'string', 'children': [], 'value': '"timestamp_start"'},{'id': '199', 'type': 'else_clause', 'children': ['200']},{'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': 'timestamp'},{'id': '204', 'type': 'subscript', 'children': ['205', '208']},{'id': '205', 'type': 'subscript', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'meta_data'},{'id': '207', 'type': 'integer', 'children': [], 'value': '0'},{'id': '208', 'type': 'string', 'children': [], 'value': '"timestamp"'},{'id': '209', 'type': 'except_clause', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'id': '211', 'type': 'block', 'children': ['212']},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'call', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'binary_operator', 'children': ['219', '220'], 'value': '%'},{'id': '219', 'type': 'string', 'children': [], 'value': '"File %s has empty meta_data"'},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'h5_file'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '223', 'type': 'else_clause', 'children': ['224']},{'id': '224', 'type': 'block', 'children': ['225']},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '230']},{'id': '227', 'type': 'subscript', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'f_list'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'data_file'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'timestamp'},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'data_files'},{'id': '234', 'type': 'call', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'call', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '239', 'type': 'argument_list', 'children': ['240', '241', '246']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'f_list'},{'id': '241', 'type': 'keyword_argument', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'f_list'},{'id': '245', 'type': 'identifier', 'children': [], 'value': '__getitem__'},{'id': '246', 'type': 'keyword_argument', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '248', 'type': 'False', 'children': []},{'id': '249', 'type': 'return_statement', 'children': ['250']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'data_files'} | def get_data_file_names_from_scan_base(scan_base, filter_str=['_analyzed.h5', '_interpreted.h5', '_cut.h5', '_result.h5', '_hists.h5'], sort_by_time=True, meta_data_v2=True):
data_files = []
if scan_base is None:
return data_files
if isinstance(scan_base, basestring):
scan_base = [scan_base]
for scan_base_str in scan_base:
if '.h5' == os.path.splitext(scan_base_str)[1]:
data_files.append(scan_base_str)
else:
data_files.extend(glob.glob(scan_base_str + '*.h5'))
if filter_str:
if isinstance(filter_str, basestring):
filter_str = [filter_str]
data_files = filter(lambda data_file: not any([(True if x in data_file else False) for x in filter_str]), data_files)
if sort_by_time and len(data_files) > 1:
f_list = {}
for data_file in data_files:
with tb.open_file(data_file, mode="r") as h5_file:
try:
meta_data = h5_file.root.meta_data
except tb.NoSuchNodeError:
logging.warning("File %s is missing meta_data" % h5_file.filename)
else:
try:
if meta_data_v2:
timestamp = meta_data[0]["timestamp_start"]
else:
timestamp = meta_data[0]["timestamp"]
except IndexError:
logging.info("File %s has empty meta_data" % h5_file.filename)
else:
f_list[data_file] = timestamp
data_files = list(sorted(f_list, key=f_list.__getitem__, reverse=False))
return data_files |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_parameter_from_files'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '13', 'type': 'True', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '17', '41', '49', '61', '73', '87', '376']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'string', 'children': [], 'value': "''' Takes a list of files, searches for the parameter name in the file name and in the file.\n Returns a ordered dict with the file name in the first dimension and the corresponding parameter values in the second.\n If a scan parameter appears in the file name and in the file the first parameter setting has to be in the file name, otherwise a warning is shown.\n The file names can be sorted by the first parameter value of each file.\n Parameters\n ----------\n files : string, list of strings\n parameters : string, list of strings\n unique : boolean\n If set only one file per scan parameter value is used.\n sort : boolean\n Returns\n -------\n collections.OrderedDict\n '''"},{'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': 'logging'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'binary_operator', 'children': ['24', '40'], 'value': '+'},{'id': '24', 'type': 'binary_operator', 'children': ['25', '33'], 'value': '+'},{'id': '25', 'type': 'binary_operator', 'children': ['26', '32'], 'value': '+'},{'id': '26', 'type': 'binary_operator', 'children': ['27', '28'], 'value': '+'},{'id': '27', 'type': 'string', 'children': [], 'value': "'Get the parameter '"},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '32', 'type': 'string', 'children': [], 'value': "' values from '"},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '40', 'type': 'string', 'children': [], 'value': "' files'"},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'files_dict'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '48', 'type': 'argument_list', 'children': []},{'id': '49', 'type': 'if_statement', 'children': ['50', '55']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'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': 'files'},{'id': '59', 'type': 'tuple', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '61', 'type': 'if_statement', 'children': ['62', '67']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '64', 'type': 'argument_list', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '71', 'type': 'tuple', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'parameter_values_from_file_names_dict'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'get_parameter_value_from_file_names'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80', '81', '84']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '87', 'type': 'for_statement', 'children': ['88', '89', '90']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'file_name'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'with_statement', 'children': ['92', '106']},{'id': '92', 'type': 'with_clause', 'children': ['93']},{'id': '93', 'type': 'with_item', 'children': ['94']},{'id': '94', 'type': 'as_pattern', 'children': ['95', '104']},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'tb'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'open_file'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'file_name'},{'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '103', 'type': 'string', 'children': [], 'value': '"r"'},{'id': '104', 'type': 'as_pattern_target', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'in_file_h5'},{'id': '106', 'type': 'block', 'children': ['107', '115', '218', '300']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'scan_parameter_values'},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '114', 'type': 'argument_list', 'children': []},{'id': '115', 'type': 'try_statement', 'children': ['116', '167']},{'id': '116', 'type': 'block', 'children': ['117', '128', '140']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'scan_parameters'},{'id': '120', 'type': 'subscript', 'children': ['121', '126']},{'id': '121', 'type': 'attribute', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'in_file_h5'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'scan_parameters'},{'id': '126', 'type': 'slice', 'children': ['127']},{'id': '127', 'type': 'colon', 'children': []},{'id': '128', 'type': 'if_statement', 'children': ['129', '132']},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': 'is'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '131', 'type': 'None', 'children': []},{'id': '132', 'type': 'block', 'children': ['133']},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'get_scan_parameter_names'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'scan_parameters'},{'id': '140', 'type': 'for_statement', 'children': ['141', '142', '143']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '143', 'type': 'block', 'children': ['144']},{'id': '144', 'type': 'try_statement', 'children': ['145', '163']},{'id': '145', 'type': 'block', 'children': ['146']},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '151']},{'id': '148', 'type': 'subscript', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'scan_parameter_values'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '151', 'type': 'call', 'children': ['152', '162']},{'id': '152', 'type': 'attribute', 'children': ['153', '161']},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'scan_parameters'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'tolist'},{'id': '162', 'type': 'argument_list', 'children': []},{'id': '163', 'type': 'except_clause', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '165', 'type': 'block', 'children': ['166']},{'id': '166', 'type': 'pass_statement', 'children': []},{'id': '167', 'type': 'except_clause', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'tb'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'NoSuchNodeError'},{'id': '171', 'type': 'block', 'children': ['172']},{'id': '172', 'type': 'try_statement', 'children': ['173', '212']},{'id': '173', 'type': 'block', 'children': ['174', '188']},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'scan_parameters'},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'get_scan_parameter'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'subscript', 'children': ['181', '186']},{'id': '181', 'type': 'attribute', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'in_file_h5'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'meta_data'},{'id': '186', 'type': 'slice', 'children': ['187']},{'id': '187', 'type': 'colon', 'children': []},{'id': '188', 'type': 'if_statement', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'scan_parameters'},{'id': '190', 'type': 'block', 'children': ['191']},{'id': '191', 'type': 'try_statement', 'children': ['192', '208']},{'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': 'scan_parameter_values'},{'id': '196', 'type': 'call', 'children': ['197', '207']},{'id': '197', 'type': 'attribute', 'children': ['198', '206']},{'id': '198', 'type': 'call', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'subscript', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'scan_parameters'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'tolist'},{'id': '207', 'type': 'argument_list', 'children': []},{'id': '208', 'type': 'except_clause', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '210', 'type': 'block', 'children': ['211']},{'id': '211', 'type': 'pass_statement', 'children': []},{'id': '212', 'type': 'except_clause', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'tb'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'NoSuchNodeError'},{'id': '216', 'type': 'block', 'children': ['217']},{'id': '217', 'type': 'pass_statement', 'children': []},{'id': '218', 'type': 'if_statement', 'children': ['219', '221', '237']},{'id': '219', 'type': 'not_operator', 'children': ['220']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'scan_parameter_values'},{'id': '221', 'type': 'block', 'children': ['222']},{'id': '222', 'type': 'try_statement', 'children': ['223', '230']},{'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': 'scan_parameter_values'},{'id': '227', 'type': 'subscript', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'parameter_values_from_file_names_dict'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'file_name'},{'id': '230', 'type': 'except_clause', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '232', 'type': 'block', 'children': ['233']},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'assignment', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'scan_parameter_values'},{'id': '236', 'type': 'None', 'children': []},{'id': '237', 'type': 'else_clause', 'children': ['238']},{'id': '238', 'type': 'block', 'children': ['239']},{'id': '239', 'type': 'try_statement', 'children': ['240', '288', '292']},{'id': '240', 'type': 'block', 'children': ['241']},{'id': '241', 'type': 'for_statement', 'children': ['242', '245', '250']},{'id': '242', 'type': 'pattern_list', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '245', 'type': 'call', 'children': ['246', '249']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'scan_parameter_values'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '249', 'type': 'argument_list', 'children': []},{'id': '250', 'type': 'block', 'children': ['251']},{'id': '251', 'type': 'if_statement', 'children': ['252', '265']},{'id': '252', 'type': 'boolean_operator', 'children': ['253', '254'], 'value': 'and'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '254', 'type': 'comparison_operator', 'children': ['255', '258'], 'value': '!='},{'id': '255', 'type': 'subscript', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '257', 'type': 'integer', 'children': [], 'value': '0'},{'id': '258', 'type': 'subscript', 'children': ['259', '264']},{'id': '259', 'type': 'subscript', 'children': ['260', '263']},{'id': '260', 'type': 'subscript', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'parameter_values_from_file_names_dict'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'file_name'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '264', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'logging'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '271', 'type': 'argument_list', 'children': ['272', '287']},{'id': '272', 'type': 'binary_operator', 'children': ['273', '286'], 'value': '+'},{'id': '273', 'type': 'binary_operator', 'children': ['274', '282'], 'value': '+'},{'id': '274', 'type': 'binary_operator', 'children': ['275', '281'], 'value': '+'},{'id': '275', 'type': 'binary_operator', 'children': ['276', '277'], 'value': '+'},{'id': '276', 'type': 'string', 'children': [], 'value': "'Parameter values in the file name and in the file differ. Take '"},{'id': '277', 'type': 'call', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '279', 'type': 'argument_list', 'children': ['280']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '281', 'type': 'string', 'children': [], 'value': "' parameters '"},{'id': '282', 'type': 'call', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '284', 'type': 'argument_list', 'children': ['285']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '286', 'type': 'string', 'children': [], 'value': "' found in %s.'"},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'file_name'},{'id': '288', 'type': 'except_clause', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '290', 'type': 'block', 'children': ['291']},{'id': '291', 'type': 'pass_statement', 'children': []},{'id': '292', 'type': 'except_clause', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'id': '294', 'type': 'block', 'children': ['295']},{'id': '295', 'type': 'raise_statement', 'children': ['296']},{'id': '296', 'type': 'call', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'IncompleteInputError'},{'id': '298', 'type': 'argument_list', 'children': ['299']},{'id': '299', 'type': 'string', 'children': [], 'value': "'Something wrong check!'"},{'id': '300', 'type': 'if_statement', 'children': ['301', '306', '368']},{'id': '301', 'type': 'boolean_operator', 'children': ['302', '303'], 'value': 'and'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '303', 'type': 'comparison_operator', 'children': ['304', '305'], 'value': 'is'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'scan_parameter_values'},{'id': '305', 'type': 'None', 'children': []},{'id': '306', 'type': 'block', 'children': ['307', '311', '348']},{'id': '307', 'type': 'expression_statement', 'children': ['308']},{'id': '308', 'type': 'assignment', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'existing'},{'id': '310', 'type': 'False', 'children': []},{'id': '311', 'type': 'for_statement', 'children': ['312', '313', '314']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'scan_parameter_values'},{'id': '314', 'type': 'block', 'children': ['315', '329']},{'id': '315', 'type': 'expression_statement', 'children': ['316']},{'id': '316', 'type': 'assignment', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'all_par_values'},{'id': '318', 'type': 'list_comprehension', 'children': ['319', '322']},{'id': '319', 'type': 'subscript', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '322', 'type': 'for_in_clause', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '324', 'type': 'call', 'children': ['325', '328']},{'id': '325', 'type': 'attribute', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'files_dict'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '328', 'type': 'argument_list', 'children': []},{'id': '329', 'type': 'if_statement', 'children': ['330', '342']},{'id': '330', 'type': 'call', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '332', 'type': 'generator_expression', 'children': ['333', '339']},{'id': '333', 'type': 'comparison_operator', 'children': ['334', '335'], 'value': 'in'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '335', 'type': 'list', 'children': ['336'], 'value': '[scan_parameter_values[parameter]]'},{'id': '336', 'type': 'subscript', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'scan_parameter_values'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '339', 'type': 'for_in_clause', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'all_par_values'},{'id': '342', 'type': 'block', 'children': ['343', '347']},{'id': '343', 'type': 'expression_statement', 'children': ['344']},{'id': '344', 'type': 'assignment', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'existing'},{'id': '346', 'type': 'True', 'children': []},{'id': '347', 'type': 'break_statement', 'children': []},{'id': '348', 'type': 'if_statement', 'children': ['349', '351', '358']},{'id': '349', 'type': 'not_operator', 'children': ['350']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'existing'},{'id': '351', 'type': 'block', 'children': ['352']},{'id': '352', 'type': 'expression_statement', 'children': ['353']},{'id': '353', 'type': 'assignment', 'children': ['354', '357']},{'id': '354', 'type': 'subscript', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'files_dict'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'file_name'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'scan_parameter_values'},{'id': '358', 'type': 'else_clause', 'children': ['359']},{'id': '359', 'type': 'block', 'children': ['360']},{'id': '360', 'type': 'expression_statement', 'children': ['361']},{'id': '361', 'type': 'call', 'children': ['362', '365']},{'id': '362', 'type': 'attribute', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '365', 'type': 'argument_list', 'children': ['366', '367']},{'id': '366', 'type': 'string', 'children': [], 'value': "'Scan parameter value(s) from %s exists already, do not add to result'"},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'file_name'},{'id': '368', 'type': 'else_clause', 'children': ['369']},{'id': '369', 'type': 'block', 'children': ['370']},{'id': '370', 'type': 'expression_statement', 'children': ['371']},{'id': '371', 'type': 'assignment', 'children': ['372', '375']},{'id': '372', 'type': 'subscript', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'files_dict'},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'file_name'},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'scan_parameter_values'},{'id': '376', 'type': 'return_statement', 'children': ['377']},{'id': '377', 'type': 'call', 'children': ['378', '381']},{'id': '378', 'type': 'attribute', 'children': ['379', '380']},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '381', 'type': 'argument_list', 'children': ['382']},{'id': '382', 'type': 'conditional_expression', 'children': ['383', '397', '398'], 'value': 'if'},{'id': '383', 'type': 'call', 'children': ['384', '385']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '385', 'type': 'argument_list', 'children': ['386', '391']},{'id': '386', 'type': 'call', 'children': ['387', '390']},{'id': '387', 'type': 'attribute', 'children': ['388', '389']},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'files_dict'},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '390', 'type': 'argument_list', 'children': []},{'id': '391', 'type': 'keyword_argument', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '393', 'type': 'call', 'children': ['394', '395']},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'itemgetter'},{'id': '395', 'type': 'argument_list', 'children': ['396']},{'id': '396', 'type': 'integer', 'children': [], 'value': '1'},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '398', 'type': 'identifier', 'children': [], 'value': 'files_dict'} | def get_parameter_from_files(files, parameters=None, unique=False, sort=True):
''' Takes a list of files, searches for the parameter name in the file name and in the file.
Returns a ordered dict with the file name in the first dimension and the corresponding parameter values in the second.
If a scan parameter appears in the file name and in the file the first parameter setting has to be in the file name, otherwise a warning is shown.
The file names can be sorted by the first parameter value of each file.
Parameters
----------
files : string, list of strings
parameters : string, list of strings
unique : boolean
If set only one file per scan parameter value is used.
sort : boolean
Returns
-------
collections.OrderedDict
'''
logging.debug('Get the parameter ' + str(parameters) + ' values from ' + str(len(files)) + ' files')
files_dict = collections.OrderedDict()
if isinstance(files, basestring):
files = (files, )
if isinstance(parameters, basestring):
parameters = (parameters, )
parameter_values_from_file_names_dict = get_parameter_value_from_file_names(files, parameters, unique=unique, sort=sort)
for file_name in files:
with tb.open_file(file_name, mode="r") as in_file_h5:
scan_parameter_values = collections.OrderedDict()
try:
scan_parameters = in_file_h5.root.scan_parameters[:]
if parameters is None:
parameters = get_scan_parameter_names(scan_parameters)
for parameter in parameters:
try:
scan_parameter_values[parameter] = np.unique(scan_parameters[parameter]).tolist()
except ValueError:
pass
except tb.NoSuchNodeError:
try:
scan_parameters = get_scan_parameter(in_file_h5.root.meta_data[:])
if scan_parameters:
try:
scan_parameter_values = np.unique(scan_parameters[parameters]).tolist()
except ValueError:
pass
except tb.NoSuchNodeError:
pass
if not scan_parameter_values:
try:
scan_parameter_values = parameter_values_from_file_names_dict[file_name]
except KeyError:
scan_parameter_values = None
else:
try:
for key, value in scan_parameter_values.items():
if value and value[0] != parameter_values_from_file_names_dict[file_name][key][0]:
logging.warning('Parameter values in the file name and in the file differ. Take ' + str(key) + ' parameters ' + str(value) + ' found in %s.', file_name)
except KeyError:
pass
except IndexError:
raise IncompleteInputError('Something wrong check!')
if unique and scan_parameter_values is not None:
existing = False
for parameter in scan_parameter_values:
all_par_values = [values[parameter] for values in files_dict.values()]
if any(x in [scan_parameter_values[parameter]] for x in all_par_values):
existing = True
break
if not existing:
files_dict[file_name] = scan_parameter_values
else:
logging.warning('Scan parameter value(s) from %s exists already, do not add to result', file_name)
else:
files_dict[file_name] = scan_parameter_values
return collections.OrderedDict(sorted(files_dict.iteritems(), key=itemgetter(1)) if sort else files_dict) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'reduce_sorted_to_intersect'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'ar1'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'ar2'},{'id': '6', 'type': 'block', 'children': ['7', '20', '33', '40', '46', '53', '59', '82', '93', '104', '115', '126', '135', '144', '165', '186']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'ar1'},{'id': '10', 'type': 'call', 'children': ['11', '19']},{'id': '11', 'type': 'attribute', 'children': ['12', '18']},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'ar1'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'ravel'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'ar2'},{'id': '23', 'type': 'call', 'children': ['24', '32']},{'id': '24', 'type': 'attribute', 'children': ['25', '31']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'ar2'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'ravel'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'ar1_biggest_value'},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'ar1'},{'id': '38', 'type': 'unary_operator', 'children': ['39'], 'value': '-'},{'id': '39', 'type': 'integer', 'children': [], 'value': '1'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'ar1_smallest_value'},{'id': '43', 'type': 'subscript', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'ar1'},{'id': '45', 'type': 'integer', 'children': [], 'value': '0'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'ar2_biggest_value'},{'id': '49', 'type': 'subscript', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'ar2'},{'id': '51', 'type': 'unary_operator', 'children': ['52'], 'value': '-'},{'id': '52', 'type': 'integer', 'children': [], 'value': '1'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'ar2_smallest_value'},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'ar2'},{'id': '58', 'type': 'integer', 'children': [], 'value': '0'},{'id': '59', 'type': 'if_statement', 'children': ['60', '67']},{'id': '60', 'type': 'boolean_operator', 'children': ['61', '64'], 'value': 'or'},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': '<'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'ar1_biggest_value'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'ar2_smallest_value'},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': '>'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'ar1_smallest_value'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'ar2_biggest_value'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'return_statement', 'children': ['69']},{'id': '69', 'type': 'expression_list', 'children': ['70', '76']},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'ar1'},{'id': '72', 'type': 'slice', 'children': ['73', '74', '75']},{'id': '73', 'type': 'integer', 'children': [], 'value': '0'},{'id': '74', 'type': 'colon', 'children': []},{'id': '75', 'type': 'integer', 'children': [], 'value': '0'},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'ar2'},{'id': '78', 'type': 'slice', 'children': ['79', '80', '81']},{'id': '79', 'type': 'integer', 'children': [], 'value': '0'},{'id': '80', 'type': 'colon', 'children': []},{'id': '81', 'type': 'integer', 'children': [], 'value': '0'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'min_index_ar1'},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'argmin'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': '<'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'ar1'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'ar2_smallest_value'},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'max_index_ar1'},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'argmax'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': '>'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'ar1'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'ar2_biggest_value'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'min_index_ar2'},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'argmin'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': '<'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'ar2'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'ar1_smallest_value'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'max_index_ar2'},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'argmax'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'comparison_operator', 'children': ['124', '125'], 'value': '>'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'ar2'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'ar1_biggest_value'},{'id': '126', 'type': 'if_statement', 'children': ['127', '130']},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': '<'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'min_index_ar1'},{'id': '129', 'type': 'integer', 'children': [], 'value': '0'},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'min_index_ar1'},{'id': '134', 'type': 'integer', 'children': [], 'value': '0'},{'id': '135', 'type': 'if_statement', 'children': ['136', '139']},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '138'], 'value': '<'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'min_index_ar2'},{'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': 'min_index_ar2'},{'id': '143', 'type': 'integer', 'children': [], 'value': '0'},{'id': '144', 'type': 'if_statement', 'children': ['145', '156']},{'id': '145', 'type': 'boolean_operator', 'children': ['146', '149'], 'value': 'or'},{'id': '146', 'type': 'comparison_operator', 'children': ['147', '148'], 'value': '=='},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'max_index_ar1'},{'id': '148', 'type': 'integer', 'children': [], 'value': '0'},{'id': '149', 'type': 'comparison_operator', 'children': ['150', '151'], 'value': '>'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'max_index_ar1'},{'id': '151', 'type': 'subscript', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'ar1'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '155', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'max_index_ar1'},{'id': '160', 'type': 'subscript', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'ar1'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '164', 'type': 'integer', 'children': [], 'value': '0'},{'id': '165', 'type': 'if_statement', 'children': ['166', '177']},{'id': '166', 'type': 'boolean_operator', 'children': ['167', '170'], 'value': 'or'},{'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': '=='},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'max_index_ar2'},{'id': '169', 'type': 'integer', 'children': [], 'value': '0'},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '172'], 'value': '>'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'max_index_ar2'},{'id': '172', 'type': 'subscript', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'ar2'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '176', 'type': 'integer', 'children': [], 'value': '0'},{'id': '177', 'type': 'block', 'children': ['178']},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'max_index_ar2'},{'id': '181', 'type': 'subscript', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'ar2'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '185', 'type': 'integer', 'children': [], 'value': '0'},{'id': '186', 'type': 'return_statement', 'children': ['187']},{'id': '187', 'type': 'expression_list', 'children': ['188', '194']},{'id': '188', 'type': 'subscript', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'ar1'},{'id': '190', 'type': 'slice', 'children': ['191', '192', '193']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'min_index_ar1'},{'id': '192', 'type': 'colon', 'children': []},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'max_index_ar1'},{'id': '194', 'type': 'subscript', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'ar2'},{'id': '196', 'type': 'slice', 'children': ['197', '198', '199']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'min_index_ar2'},{'id': '198', 'type': 'colon', 'children': []},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'max_index_ar2'} | def reduce_sorted_to_intersect(ar1, ar2):
ar1 = np.asarray(ar1).ravel()
ar2 = np.asarray(ar2).ravel()
ar1_biggest_value = ar1[-1]
ar1_smallest_value = ar1[0]
ar2_biggest_value = ar2[-1]
ar2_smallest_value = ar2[0]
if ar1_biggest_value < ar2_smallest_value or ar1_smallest_value > ar2_biggest_value:
return ar1[0:0], ar2[0:0]
min_index_ar1 = np.argmin(ar1 < ar2_smallest_value)
max_index_ar1 = np.argmax(ar1 > ar2_biggest_value)
min_index_ar2 = np.argmin(ar2 < ar1_smallest_value)
max_index_ar2 = np.argmax(ar2 > ar1_biggest_value)
if min_index_ar1 < 0:
min_index_ar1 = 0
if min_index_ar2 < 0:
min_index_ar2 = 0
if max_index_ar1 == 0 or max_index_ar1 > ar1.shape[0]:
max_index_ar1 = ar1.shape[0]
if max_index_ar2 == 0 or max_index_ar2 > ar2.shape[0]:
max_index_ar2 = ar2.shape[0]
return ar1[min_index_ar1:max_index_ar1], ar2[min_index_ar2:max_index_ar2] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_hits_in_events'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'hits_array'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'assume_sorted'},{'id': '8', 'type': 'True', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'condition'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '15', '27', '58', '158']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'string', 'children': [], 'value': "'''Selects the hits that occurred in events and optional selection criterion.\n If a event range can be defined use the get_data_in_event_range function. It is much faster.\n Parameters\n ----------\n hits_array : numpy.array\n events : array\n assume_sorted : bool\n Is true if the events to select are sorted from low to high value. Increases speed by 35%.\n condition : string\n A condition that is applied to the hits in numexpr. Only if the expression evaluates to True the hit is taken.\n Returns\n -------\n numpy.array\n hit array with the hits in events.\n '''"},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'binary_operator', 'children': ['22', '23'], 'value': '%'},{'id': '22', 'type': 'string', 'children': [], 'value': '"Calculate hits that exists in the given %d events."'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '27', 'type': 'if_statement', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'assume_sorted'},{'id': '29', 'type': 'block', 'children': ['30', '42']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '35']},{'id': '32', 'type': 'pattern_list', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '34', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'reduce_sorted_to_intersect'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '39', 'type': 'subscript', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'hits_array'},{'id': '41', 'type': 'string', 'children': [], 'value': "'event_number'"},{'id': '42', 'type': 'if_statement', 'children': ['43', '50']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '49'], 'value': '=='},{'id': '44', 'type': 'subscript', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '48', 'type': 'integer', 'children': [], 'value': '0'},{'id': '49', 'type': 'integer', 'children': [], 'value': '0'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'return_statement', 'children': ['52']},{'id': '52', 'type': 'subscript', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'hits_array'},{'id': '54', 'type': 'slice', 'children': ['55', '56', '57']},{'id': '55', 'type': 'integer', 'children': [], 'value': '0'},{'id': '56', 'type': 'colon', 'children': []},{'id': '57', 'type': 'integer', 'children': [], 'value': '0'},{'id': '58', 'type': 'try_statement', 'children': ['59', '146']},{'id': '59', 'type': 'block', 'children': ['60', '96']},{'id': '60', 'type': 'if_statement', 'children': ['61', '62', '75']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'assume_sorted'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'selection'},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'analysis_utils'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'in1d_events'},{'id': '70', 'type': 'argument_list', 'children': ['71', '74']},{'id': '71', 'type': 'subscript', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'hits_array'},{'id': '73', 'type': 'string', 'children': [], 'value': "'event_number'"},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '75', 'type': 'else_clause', 'children': ['76']},{'id': '76', 'type': 'block', 'children': ['77', '84']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'string', 'children': [], 'value': "'Events are usually sorted. Are you sure you want this?'"},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'selection'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'in1d'},{'id': '91', 'type': 'argument_list', 'children': ['92', '95']},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'hits_array'},{'id': '94', 'type': 'string', 'children': [], 'value': "'event_number'"},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '96', 'type': 'if_statement', 'children': ['97', '100', '107']},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': 'is'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'condition'},{'id': '99', 'type': 'None', 'children': []},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'hits_in_events'},{'id': '104', 'type': 'subscript', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'hits_array'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'selection'},{'id': '107', 'type': 'else_clause', 'children': ['108']},{'id': '108', 'type': 'block', 'children': ['109', '133']},{'id': '109', 'type': 'for_statement', 'children': ['110', '111', '121']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'variable'},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '118', 'type': 'argument_list', 'children': ['119', '120']},{'id': '119', 'type': 'string', 'children': [], 'value': "r'[a-zA-Z_]+'"},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'condition'},{'id': '121', 'type': 'block', 'children': ['122']},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'exec'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'binary_operator', 'children': ['127', '132'], 'value': '+'},{'id': '127', 'type': 'binary_operator', 'children': ['128', '131'], 'value': '+'},{'id': '128', 'type': 'binary_operator', 'children': ['129', '130'], 'value': '+'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'variable'},{'id': '130', 'type': 'string', 'children': [], 'value': "' = hits_array[\\''"},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'variable'},{'id': '132', 'type': 'string', 'children': [], 'value': "'\\']'"},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'hits_in_events'},{'id': '136', 'type': 'subscript', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'hits_array'},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'ne'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'evaluate'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'binary_operator', 'children': ['144', '145'], 'value': '+'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'condition'},{'id': '145', 'type': 'string', 'children': [], 'value': "' & selection'"},{'id': '146', 'type': 'except_clause', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'MemoryError'},{'id': '148', 'type': 'block', 'children': ['149', '156']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'string', 'children': [], 'value': "'There are too many hits to do in RAM operations. Consider decreasing chunk size and use the write_hits_in_events function instead.'"},{'id': '156', 'type': 'raise_statement', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'MemoryError'},{'id': '158', 'type': 'return_statement', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'hits_in_events'} | def get_hits_in_events(hits_array, events, assume_sorted=True, condition=None):
'''Selects the hits that occurred in events and optional selection criterion.
If a event range can be defined use the get_data_in_event_range function. It is much faster.
Parameters
----------
hits_array : numpy.array
events : array
assume_sorted : bool
Is true if the events to select are sorted from low to high value. Increases speed by 35%.
condition : string
A condition that is applied to the hits in numexpr. Only if the expression evaluates to True the hit is taken.
Returns
-------
numpy.array
hit array with the hits in events.
'''
logging.debug("Calculate hits that exists in the given %d events." % len(events))
if assume_sorted:
events, _ = reduce_sorted_to_intersect(events, hits_array['event_number'])
if events.shape[0] == 0:
return hits_array[0:0]
try:
if assume_sorted:
selection = analysis_utils.in1d_events(hits_array['event_number'], events)
else:
logging.warning('Events are usually sorted. Are you sure you want this?')
selection = np.in1d(hits_array['event_number'], events)
if condition is None:
hits_in_events = hits_array[selection]
else:
for variable in set(re.findall(r'[a-zA-Z_]+', condition)):
exec(variable + ' = hits_array[\'' + variable + '\']')
hits_in_events = hits_array[ne.evaluate(condition + ' & selection')]
except MemoryError:
logging.error('There are too many hits to do in RAM operations. Consider decreasing chunk size and use the write_hits_in_events function instead.')
raise MemoryError
return hits_in_events |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'natsorted'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'cmp'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'natcmp'},{'id': '8', 'type': 'block', 'children': ['9', '11', '14', '23', '29']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'string', 'children': [], 'value': '"Returns a copy of seq, sorted by natural string sort."'},{'id': '11', 'type': 'import_statement', 'children': ['12']},{'id': '12', 'type': 'dotted_name', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'temp'},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'natsort'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'temp'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'cmp'},{'id': '29', 'type': 'return_statement', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'temp'} | def natsorted(seq, cmp=natcmp):
"Returns a copy of seq, sorted by natural string sort."
import copy
temp = copy.copy(seq)
natsort(temp, cmp)
return temp |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort2groups'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'gpat'},{'id': '7', 'type': 'list', 'children': ['8', '9'], 'value': "['_R1','_R2']"},{'id': '8', 'type': 'string', 'children': [], 'value': "'_R1'"},{'id': '9', 'type': 'string', 'children': [], 'value': "'_R2'"},{'id': '10', 'type': 'block', 'children': ['11', '22', '26', '62']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '14', 'type': 'list_comprehension', 'children': ['15', '19']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'REGroup'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'gp'},{'id': '19', 'type': 'for_in_clause', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'gp'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'gpat'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'unmatched'},{'id': '25', 'type': 'list', 'children': [], 'value': '[]'},{'id': '26', 'type': 'for_statement', 'children': ['27', '28', '29']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '29', 'type': 'block', 'children': ['30', '34', '51']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'matched'},{'id': '33', 'type': 'False', 'children': []},{'id': '34', 'type': 'for_statement', 'children': ['35', '36', '37']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'if_statement', 'children': ['39', '45']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '45', 'type': 'block', 'children': ['46', '50']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'matched'},{'id': '49', 'type': 'True', 'children': []},{'id': '50', 'type': 'break_statement', 'children': []},{'id': '51', 'type': 'if_statement', 'children': ['52', '54']},{'id': '52', 'type': 'not_operator', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'matched'},{'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': 'unmatched'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '62', 'type': 'return_statement', 'children': ['63']},{'id': '63', 'type': 'expression_list', 'children': ['64', '74']},{'id': '64', 'type': 'list_comprehension', 'children': ['65', '71']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '71', 'type': 'for_in_clause', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'unmatched'} | def sort2groups(array, gpat=['_R1','_R2']):
groups = [REGroup(gp) for gp in gpat]
unmatched = []
for item in array:
matched = False
for m in groups:
if m.match(item):
matched = True
break
if not matched: unmatched.append(item)
return [sorted(m.list) for m in groups], sorted(unmatched) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_and_distribute'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'splits'},{'id': '7', 'type': 'integer', 'children': [], 'value': '2'},{'id': '8', 'type': 'block', 'children': ['9', '24', '37', '44', '69', '77', '111']},{'id': '9', 'type': 'if_statement', 'children': ['10', '18']},{'id': '10', 'type': 'not_operator', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '13', 'type': 'argument_list', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '15', 'type': 'tuple', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'raise_statement', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'string', 'children': [], 'value': '"array must be a list"'},{'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': 'isinstance'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'splits'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'raise_statement', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'string', 'children': [], 'value': '"splits must be an integer"'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'remaining'},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '44', 'type': 'if_statement', 'children': ['45', '52', '60']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '49'], 'value': '<'},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'version_info'},{'id': '49', 'type': 'tuple', 'children': ['50', '51']},{'id': '50', 'type': 'integer', 'children': [], 'value': '3'},{'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': 'myrange'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'xrange'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'splits'},{'id': '60', 'type': 'else_clause', 'children': ['61']},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'myrange'},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'splits'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '72', 'type': 'list_comprehension', 'children': ['73', '74']},{'id': '73', 'type': 'list', 'children': [], 'value': '[]'},{'id': '74', 'type': 'for_in_clause', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'myrange'},{'id': '77', 'type': 'while_statement', 'children': ['78', '84']},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '83'], 'value': '>'},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'remaining'},{'id': '83', 'type': 'integer', 'children': [], 'value': '0'},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'for_statement', 'children': ['86', '87', '88']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'myrange'},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'if_statement', 'children': ['90', '96']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '95'], 'value': '>'},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'remaining'},{'id': '95', 'type': 'integer', 'children': [], 'value': '0'},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '104']},{'id': '99', 'type': 'attribute', 'children': ['100', '103']},{'id': '100', 'type': 'subscript', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'remaining'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'integer', 'children': [], 'value': '0'},{'id': '111', 'type': 'return_statement', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'groups'} | def sort_and_distribute(array, splits=2):
if not isinstance(array, (list,tuple)): raise TypeError("array must be a list")
if not isinstance(splits, int): raise TypeError("splits must be an integer")
remaining = sorted(array)
if sys.version_info < (3, 0):
myrange = xrange(splits)
else:
myrange = range(splits)
groups = [[] for i in myrange]
while len(remaining) > 0:
for i in myrange:
if len(remaining) > 0: groups[i].append(remaining.pop(0))
return groups |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'section'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '21', '29', '35', '80']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '16', 'type': 'subscript', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'section'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '26']},{'id': '23', 'type': 'pattern_list', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'old_i'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'old_sort'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'sort_state'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'beginResetModel'},{'id': '34', 'type': 'argument_list', 'children': []},{'id': '35', 'type': 'if_statement', 'children': ['36', '39', '60']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': '=='},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'section'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'old_i'},{'id': '39', 'type': 'block', 'children': ['40', '51']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '47']},{'id': '42', 'type': 'attribute', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '49', 'type': 'not_operator', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'old_sort'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'sort_state'},{'id': '56', 'type': 'tuple', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'section'},{'id': '58', 'type': 'not_operator', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'old_sort'},{'id': '60', 'type': 'else_clause', 'children': ['61']},{'id': '61', 'type': 'block', 'children': ['62', '72']},{'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': 'collection'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '71', 'type': 'True', 'children': []},{'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': 'sort_state'},{'id': '77', 'type': 'tuple', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'section'},{'id': '79', 'type': 'True', 'children': []},{'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': 'endResetModel'},{'id': '85', 'type': 'argument_list', 'children': []} | def sort(self, section: int, order=None):
attr = self.header[section]
old_i, old_sort = self.sort_state
self.beginResetModel()
if section == old_i:
self.collection.sort(attr, not old_sort)
self.sort_state = (section, not old_sort)
else:
self.collection.sort(attr, True)
self.sort_state = (section, True)
self.endResetModel() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'set_collection'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '6', 'type': 'block', 'children': ['7', '13', '19', '28']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'beginResetModel'},{'id': '12', 'type': 'argument_list', 'children': []},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'sort_state'},{'id': '24', 'type': 'tuple', 'children': ['25', '27']},{'id': '25', 'type': 'unary_operator', 'children': ['26'], 'value': '-'},{'id': '26', 'type': 'integer', 'children': [], 'value': '1'},{'id': '27', 'type': 'False', 'children': []},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'endResetModel'},{'id': '33', 'type': 'argument_list', 'children': []} | def set_collection(self, collection):
self.beginResetModel()
self.collection = collection
self.sort_state = (-1, False)
self.endResetModel() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'copy'},{'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': 'items'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'return_statement', 'children': ['10']},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'NGram'},{'id': '12', 'type': 'argument_list', 'children': ['13', '19', '22', '25', '28', '31', '34']},{'id': '13', 'type': 'conditional_expression', 'children': ['14', '15', '18'], 'value': 'if'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'is'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'warp'},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_key'},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': '_pad_len'},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': '_pad_char'} | def copy(self, items=None):
return NGram(items if items is not None else self,
self.threshold, self.warp, self._key,
self.N, self._pad_len, self._pad_char) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'items_sharing_ngrams'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '6', 'type': 'block', 'children': ['7', '11', '15', '89']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'shared'},{'id': '10', 'type': 'dictionary', 'children': []},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'remaining'},{'id': '14', 'type': 'dictionary', 'children': []},{'id': '15', 'type': 'for_statement', 'children': ['16', '17', '23']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'ngram'},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'try_statement', 'children': ['25', '85']},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'for_statement', 'children': ['27', '30', '39']},{'id': '27', 'type': 'pattern_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '30', 'type': 'call', 'children': ['31', '38']},{'id': '31', 'type': 'attribute', 'children': ['32', '37']},{'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': '_grams'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'ngram'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '38', 'type': 'argument_list', 'children': []},{'id': '39', 'type': 'block', 'children': ['40', '54']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '51']},{'id': '42', 'type': 'attribute', 'children': ['43', '50']},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'remaining'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'ngram'},{'id': '49', 'type': 'dictionary', 'children': []},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '51', 'type': 'argument_list', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '54', 'type': 'if_statement', 'children': ['55', '62']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '61'], 'value': '>'},{'id': '56', 'type': 'subscript', 'children': ['57', '60']},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'remaining'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'ngram'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '61', 'type': 'integer', 'children': [], 'value': '0'},{'id': '62', 'type': 'block', 'children': ['63', '71', '79']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'augmented_assignment', 'children': ['65', '70'], 'value': '-='},{'id': '65', 'type': 'subscript', 'children': ['66', '69']},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'remaining'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'ngram'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '70', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'shared'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '78', 'type': 'integer', 'children': [], 'value': '0'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'augmented_assignment', 'children': ['81', '84'], 'value': '+='},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'shared'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '84', 'type': 'integer', 'children': [], 'value': '1'},{'id': '85', 'type': 'except_clause', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'pass_statement', 'children': []},{'id': '89', 'type': 'return_statement', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'shared'} | def items_sharing_ngrams(self, query):
shared = {}
remaining = {}
for ngram in self.split(query):
try:
for match, count in self._grams[ngram].items():
remaining.setdefault(ngram, {}).setdefault(match, count)
if remaining[ngram][match] > 0:
remaining[ngram][match] -= 1
shared.setdefault(match, 0)
shared[match] += 1
except KeyError:
pass
return shared |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'searchitem'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10']},{'id': '10', 'type': 'return_statement', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '15', 'type': 'argument_list', 'children': ['16', '22']},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'threshold'} | def searchitem(self, item, threshold=None):
return self.search(self.key(item), threshold) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'search'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '21', '25', '97', '114']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '13', 'type': 'conditional_expression', 'children': ['14', '15', '18'], 'value': 'if'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'is'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '24', 'type': 'list', 'children': [], 'value': '[]'},{'id': '25', 'type': 'for_statement', 'children': ['26', '29', '39']},{'id': '26', 'type': 'pattern_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'samegrams'},{'id': '29', 'type': 'call', 'children': ['30', '38']},{'id': '30', 'type': 'attribute', 'children': ['31', '37']},{'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': 'items_sharing_ngrams'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '38', 'type': 'argument_list', 'children': []},{'id': '39', 'type': 'block', 'children': ['40', '70', '83']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'allgrams'},{'id': '43', 'type': '()', 'children': ['44']},{'id': '44', 'type': 'binary_operator', 'children': ['45', '69'], 'value': '+'},{'id': '45', 'type': 'binary_operator', 'children': ['46', '68'], 'value': '-'},{'id': '46', 'type': 'binary_operator', 'children': ['47', '62'], 'value': '-'},{'id': '47', 'type': 'binary_operator', 'children': ['48', '57'], 'value': '+'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'pad'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '57', 'type': 'subscript', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '62', 'type': '()', 'children': ['63']},{'id': '63', 'type': 'binary_operator', 'children': ['64', '65'], 'value': '*'},{'id': '64', 'type': 'integer', 'children': [], 'value': '2'},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'samegrams'},{'id': '69', 'type': 'integer', 'children': [], 'value': '2'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'similarity'},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'ngram_similarity'},{'id': '77', 'type': 'argument_list', 'children': ['78', '79', '80']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'samegrams'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'allgrams'},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'warp'},{'id': '83', 'type': 'if_statement', 'children': ['84', '87']},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': '>='},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'similarity'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'tuple', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'similarity'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '102', 'type': 'argument_list', 'children': ['103', '111']},{'id': '103', 'type': 'keyword_argument', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '105', 'type': 'lambda', 'children': ['106', '108']},{'id': '106', 'type': 'lambda_parameters', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '108', 'type': 'subscript', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '110', 'type': 'integer', 'children': [], 'value': '1'},{'id': '111', 'type': 'keyword_argument', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '113', 'type': 'True', 'children': []},{'id': '114', 'type': 'return_statement', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'results'} | def search(self, query, threshold=None):
threshold = threshold if threshold is not None else self.threshold
results = []
for match, samegrams in self.items_sharing_ngrams(query).items():
allgrams = (len(self.pad(query))
+ self.length[match] - (2 * self.N) - samegrams + 2)
similarity = self.ngram_similarity(samegrams, allgrams, self.warp)
if similarity >= threshold:
results.append((match, similarity))
results.sort(key=lambda x: x[1], reverse=True)
return results |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'clear'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '16', '22']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'call', 'children': ['8', '15']},{'id': '8', 'type': 'attribute', 'children': ['9', '14']},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '11', 'type': 'argument_list', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'NGram'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'clear'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_grams'},{'id': '21', 'type': 'dictionary', 'children': []},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '27', 'type': 'dictionary', 'children': []} | def clear(self):
super(NGram, self).clear()
self._grams = {}
self.length = {} |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'union'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'others'},{'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': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '22']},{'id': '15', 'type': 'attribute', 'children': ['16', '21']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '18', 'type': 'argument_list', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'NGram'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'union'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'list_splat', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'others'} | def union(self, *others):
return self.copy(super(NGram, self).union(*others)) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'symmetric_difference'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'return_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '21']},{'id': '14', 'type': 'attribute', 'children': ['15', '20']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'NGram'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'symmetric_difference'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'other'} | def symmetric_difference(self, other):
return self.copy(super(NGram, self).symmetric_difference(other)) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'symmetric_difference_update'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '6', 'type': 'block', 'children': ['7', '20', '27']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'intersection'},{'id': '10', 'type': 'call', 'children': ['11', '18']},{'id': '11', 'type': 'attribute', 'children': ['12', '17']},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '14', 'type': 'argument_list', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'NGram'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'intersection'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'other'},{'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': 'difference_update'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'intersection'} | def symmetric_difference_update(self, other):
intersection = super(NGram, self).intersection(other)
self.update(other)
self.difference_update(intersection) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '38']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'download'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32', '35']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'master_token'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'access_token'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'project_data'},{'id': '19', 'type': 'False', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'max_size'},{'id': '22', 'type': 'string', 'children': [], 'value': "'128m'"},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '25', 'type': 'False', 'children': []},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '28', 'type': 'False', 'children': []},{'id': '29', 'type': 'default_parameter', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'memberlist'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'default_parameter', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'excludelist'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'default_parameter', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'id_filename'},{'id': '37', 'type': 'False', 'children': []},{'id': '38', 'type': 'block', 'children': ['39', '45', '63', '70', '77', '96', '109']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'set_log_level'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '45', 'type': 'if_statement', 'children': ['46', '55']},{'id': '46', 'type': 'boolean_operator', 'children': ['47', '51'], 'value': 'and'},{'id': '47', 'type': '()', 'children': ['48']},{'id': '48', 'type': 'boolean_operator', 'children': ['49', '50'], 'value': 'or'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'memberlist'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'excludelist'},{'id': '51', 'type': '()', 'children': ['52']},{'id': '52', 'type': 'boolean_operator', 'children': ['53', '54'], 'value': 'or'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'access_token'},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'raise_statement', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'UsageError'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'concatenated_string', 'children': ['61', '62']},{'id': '61', 'type': 'string', 'children': [], 'value': "'Please do not provide a memberlist or excludelist '"},{'id': '62', 'type': 'string', 'children': [], 'value': "'when retrieving data for a single member.'"},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'memberlist'},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'read_id_list'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'memberlist'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'excludelist'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'read_id_list'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'excludelist'},{'id': '77', 'type': 'if_statement', 'children': ['78', '88']},{'id': '78', 'type': 'boolean_operator', 'children': ['79', '84'], 'value': 'or'},{'id': '79', 'type': 'not_operator', 'children': ['80']},{'id': '80', 'type': '()', 'children': ['81']},{'id': '81', 'type': 'boolean_operator', 'children': ['82', '83'], 'value': 'or'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'master_token'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'access_token'},{'id': '84', 'type': '()', 'children': ['85']},{'id': '85', 'type': 'boolean_operator', 'children': ['86', '87'], 'value': 'and'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'master_token'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'access_token'},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'raise_statement', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'UsageError'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'concatenated_string', 'children': ['94', '95']},{'id': '94', 'type': 'string', 'children': [], 'value': "'Please specify either a master access token (-T), '"},{'id': '95', 'type': 'string', 'children': [], 'value': "'or an OAuth2 user access token (-t).'"},{'id': '96', 'type': 'if_statement', 'children': ['97', '101']},{'id': '97', 'type': '()', 'children': ['98']},{'id': '98', 'type': 'boolean_operator', 'children': ['99', '100'], 'value': 'and'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'project_data'},{'id': '101', 'type': 'block', 'children': ['102']},{'id': '102', 'type': 'raise_statement', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'UsageError'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'concatenated_string', 'children': ['107', '108']},{'id': '107', 'type': 'string', 'children': [], 'value': '"It doesn\'t make sense to use both \'source\' and"'},{'id': '108', 'type': 'string', 'children': [], 'value': '"\'project-data\' options!"'},{'id': '109', 'type': 'if_statement', 'children': ['110', '111', '205']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'master_token'},{'id': '111', 'type': 'block', 'children': ['112', '121']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'project'},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'OHProject'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'master_access_token'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'master_token'},{'id': '121', 'type': 'if_statement', 'children': ['122', '123', '176']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '123', 'type': 'block', 'children': ['124']},{'id': '124', 'type': 'if_statement', 'children': ['125', '126', '149']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'project_data'},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'project'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'download_member_project_data'},{'id': '132', 'type': 'argument_list', 'children': ['133', '140', '143', '146']},{'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'member_data'},{'id': '135', 'type': 'subscript', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'project'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'project_data'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '140', 'type': 'keyword_argument', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'target_member_dir'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '143', 'type': 'keyword_argument', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'max_size'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'max_size'},{'id': '146', 'type': 'keyword_argument', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'id_filename'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'id_filename'},{'id': '149', 'type': 'else_clause', 'children': ['150']},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'project'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'download_member_shared'},{'id': '156', 'type': 'argument_list', 'children': ['157', '164', '167', '170', '173']},{'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'member_data'},{'id': '159', 'type': 'subscript', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'project'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'project_data'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '164', 'type': 'keyword_argument', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'target_member_dir'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '167', 'type': 'keyword_argument', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '170', 'type': 'keyword_argument', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'max_size'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'max_size'},{'id': '173', 'type': 'keyword_argument', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'id_filename'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'id_filename'},{'id': '176', 'type': 'else_clause', 'children': ['177']},{'id': '177', 'type': 'block', 'children': ['178']},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'call', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'project'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'download_all'},{'id': '183', 'type': 'argument_list', 'children': ['184', '187', '190', '193', '196', '199', '202']},{'id': '184', 'type': 'keyword_argument', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'target_dir'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '187', 'type': 'keyword_argument', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '190', 'type': 'keyword_argument', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'max_size'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'max_size'},{'id': '193', 'type': 'keyword_argument', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'memberlist'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'memberlist'},{'id': '196', 'type': 'keyword_argument', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'excludelist'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'excludelist'},{'id': '199', 'type': 'keyword_argument', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'project_data'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'project_data'},{'id': '202', 'type': 'keyword_argument', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'id_filename'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'id_filename'},{'id': '205', 'type': 'else_clause', 'children': ['206']},{'id': '206', 'type': 'block', 'children': ['207', '217']},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'member_data'},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'exchange_oauth2_member'},{'id': '212', 'type': 'argument_list', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'access_token'},{'id': '214', 'type': 'keyword_argument', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'all_files'},{'id': '216', 'type': 'True', 'children': []},{'id': '217', 'type': 'if_statement', 'children': ['218', '219', '238']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'project_data'},{'id': '219', 'type': 'block', 'children': ['220']},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'OHProject'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'download_member_project_data'},{'id': '225', 'type': 'argument_list', 'children': ['226', '229', '232', '235']},{'id': '226', 'type': 'keyword_argument', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'member_data'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'member_data'},{'id': '229', 'type': 'keyword_argument', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'target_member_dir'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '232', 'type': 'keyword_argument', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'max_size'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'max_size'},{'id': '235', 'type': 'keyword_argument', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'id_filename'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'id_filename'},{'id': '238', 'type': 'else_clause', 'children': ['239']},{'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': 'OHProject'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'download_member_shared'},{'id': '245', 'type': 'argument_list', 'children': ['246', '249', '252', '255', '258']},{'id': '246', 'type': 'keyword_argument', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'member_data'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'member_data'},{'id': '249', 'type': 'keyword_argument', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'target_member_dir'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '252', 'type': 'keyword_argument', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '255', 'type': 'keyword_argument', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'max_size'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'max_size'},{'id': '258', 'type': 'keyword_argument', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'id_filename'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'id_filename'} | def download(directory, master_token=None, member=None, access_token=None,
source=None, project_data=False, max_size='128m', verbose=False,
debug=False, memberlist=None, excludelist=None,
id_filename=False):
set_log_level(debug, verbose)
if (memberlist or excludelist) and (member or access_token):
raise UsageError('Please do not provide a memberlist or excludelist '
'when retrieving data for a single member.')
memberlist = read_id_list(memberlist)
excludelist = read_id_list(excludelist)
if not (master_token or access_token) or (master_token and access_token):
raise UsageError('Please specify either a master access token (-T), '
'or an OAuth2 user access token (-t).')
if (source and project_data):
raise UsageError("It doesn't make sense to use both 'source' and"
"'project-data' options!")
if master_token:
project = OHProject(master_access_token=master_token)
if member:
if project_data:
project.download_member_project_data(
member_data=project.project_data[member],
target_member_dir=directory,
max_size=max_size,
id_filename=id_filename)
else:
project.download_member_shared(
member_data=project.project_data[member],
target_member_dir=directory,
source=source,
max_size=max_size,
id_filename=id_filename)
else:
project.download_all(target_dir=directory,
source=source,
max_size=max_size,
memberlist=memberlist,
excludelist=excludelist,
project_data=project_data,
id_filename=id_filename)
else:
member_data = exchange_oauth2_member(access_token, all_files=True)
if project_data:
OHProject.download_member_project_data(member_data=member_data,
target_member_dir=directory,
max_size=max_size,
id_filename=id_filename)
else:
OHProject.download_member_shared(member_data=member_data,
target_member_dir=directory,
source=source,
max_size=max_size,
id_filename=id_filename) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '9', 'type': 'block', 'children': ['10', '22', '116', '129']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sorts'},{'id': '13', 'type': 'call', 'children': ['14', '19']},{'id': '14', 'type': 'attribute', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'meta'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21']},{'id': '20', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '21', 'type': 'list', 'children': [], 'value': '[]'},{'id': '22', 'type': 'for_statement', 'children': ['23', '24', '25']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '25', 'type': 'block', 'children': ['26', '94', '107']},{'id': '26', 'type': 'if_statement', 'children': ['27', '32', '39', '82']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'Column'},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'identifier'},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '39', 'type': 'elif_clause', 'children': ['40', '47']},{'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': 'column'},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'id': '47', 'type': 'block', 'children': ['48', '65']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'descending'},{'id': '51', 'type': 'boolean_operator', 'children': ['52', '58'], 'value': 'or'},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'string', 'children': [], 'value': "'descending'"},{'id': '64', 'type': 'False', 'children': []},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'identifier'},{'id': '68', 'type': 'attribute', 'children': ['69', '81']},{'id': '69', 'type': 'subscript', 'children': ['70', '75']},{'id': '70', 'type': 'attribute', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'api'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'lstrip'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '82', 'type': 'else_clause', 'children': ['83']},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'raise_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'string', 'children': [], 'value': '"Can only sort on columns or column strings. Received: {}"'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '94', 'type': 'if_statement', 'children': ['95', '96', '101']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'descending'},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '100', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '101', 'type': 'else_clause', 'children': ['102']},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '106', 'type': 'string', 'children': [], 'value': "''"},{'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': 'sorts'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'binary_operator', 'children': ['114', '115'], 'value': '+'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'identifier'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '123']},{'id': '118', 'type': 'subscript', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'raw'},{'id': '122', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '123', 'type': 'call', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'string', 'children': [], 'value': '","'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'sorts'},{'id': '129', 'type': 'return_statement', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'} | def sort(self, *columns, **options):
sorts = self.meta.setdefault('sort', [])
for column in columns:
if isinstance(column, Column):
identifier = column.id
elif isinstance(column, utils.basestring):
descending = column.startswith('-') or options.get('descending', False)
identifier = self.api.columns[column.lstrip('-')].id
else:
raise ValueError("Can only sort on columns or column strings. Received: {}".format(column))
if descending:
sign = '-'
else:
sign = ''
sorts.append(sign + identifier)
self.raw['sort'] = ",".join(sorts)
return self |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'getList'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'aspList'},{'id': '6', 'type': 'block', 'children': ['7', '23', '39', '55', '63', '78', '86', '102', '118', '128', '132', '204']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '14', 'type': 'argument_list', 'children': ['15', '18', '21']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'SIG_OBJECTS'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '21', 'type': 'list', 'children': ['22'], 'value': '[0]'},{'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': 'houses'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '30', 'type': 'argument_list', 'children': ['31', '34', '37']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'SIG_HOUSES'},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '37', 'type': 'list', 'children': ['38'], 'value': '[0]'},{'id': '38', 'type': 'integer', 'children': [], 'value': '0'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'angles'},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '46', 'type': 'argument_list', 'children': ['47', '50', '53']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'SIG_ANGLES'},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '53', 'type': 'list', 'children': ['54'], 'value': '[0]'},{'id': '54', 'type': 'integer', 'children': [], 'value': '0'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'significators'},{'id': '58', 'type': 'binary_operator', 'children': ['59', '62'], 'value': '+'},{'id': '59', 'type': 'binary_operator', 'children': ['60', '61'], 'value': '+'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'houses'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'angles'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'objects'},{'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': '_elements'},{'id': '70', 'type': 'argument_list', 'children': ['71', '74', '77']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'SIG_OBJECTS'},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'aspList'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'terms'},{'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': '_terms'},{'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': 'antiscias'},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '92', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '93', 'type': 'argument_list', 'children': ['94', '97', '100']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'SIG_OBJECTS'},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '100', 'type': 'list', 'children': ['101'], 'value': '[0]'},{'id': '101', 'type': 'integer', 'children': [], 'value': '0'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'cantiscias'},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '108', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '109', 'type': 'argument_list', 'children': ['110', '113', '116']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'SIG_OBJECTS'},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'C'},{'id': '116', 'type': 'list', 'children': ['117'], 'value': '[0]'},{'id': '117', 'type': 'integer', 'children': [], 'value': '0'},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'promissors'},{'id': '121', 'type': 'binary_operator', 'children': ['122', '127'], 'value': '+'},{'id': '122', 'type': 'binary_operator', 'children': ['123', '126'], 'value': '+'},{'id': '123', 'type': 'binary_operator', 'children': ['124', '125'], 'value': '+'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'antiscias'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'cantiscias'},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '131', 'type': 'list', 'children': [], 'value': '[]'},{'id': '132', 'type': 'for_statement', 'children': ['133', '134', '135']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'prom'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'promissors'},{'id': '135', 'type': 'block', 'children': ['136']},{'id': '136', 'type': 'for_statement', 'children': ['137', '138', '139']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'sig'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'significators'},{'id': '139', 'type': 'block', 'children': ['140', '151', '161']},{'id': '140', 'type': 'if_statement', 'children': ['141', '149']},{'id': '141', 'type': '()', 'children': ['142']},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '146'], 'value': '=='},{'id': '143', 'type': 'subscript', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'prom'},{'id': '145', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '146', 'type': 'subscript', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'sig'},{'id': '148', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'continue_statement', 'children': []},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'arcs'},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '157', 'type': 'identifier', 'children': [], 'value': '_arc'},{'id': '158', 'type': 'argument_list', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'prom'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'sig'},{'id': '161', 'type': 'for_statement', 'children': ['162', '165', '172']},{'id': '162', 'type': 'tuple_pattern', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '165', 'type': 'list', 'children': ['166', '169'], 'value': "[('arcm', 'M'), ('arcz', 'Z')]"},{'id': '166', 'type': 'tuple', 'children': ['167', '168']},{'id': '167', 'type': 'string', 'children': [], 'value': "'arcm'"},{'id': '168', 'type': 'string', 'children': [], 'value': "'M'"},{'id': '169', 'type': 'tuple', 'children': ['170', '171']},{'id': '170', 'type': 'string', 'children': [], 'value': "'arcz'"},{'id': '171', 'type': 'string', 'children': [], 'value': "'Z'"},{'id': '172', 'type': 'block', 'children': ['173', '179']},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'arc'},{'id': '176', 'type': 'subscript', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'arcs'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '179', 'type': 'if_statement', 'children': ['180', '186']},{'id': '180', 'type': 'comparison_operator', 'children': ['181', '182', '183'], 'value': '<'},{'id': '181', 'type': 'integer', 'children': [], 'value': '0'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'arc'},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'MAX_ARC'},{'id': '186', 'type': 'block', 'children': ['187']},{'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': 'res'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'list', 'children': ['194', '197', '200', '203'], 'value': "[\n arcs[x],\n prom['id'],\n sig['id'],\n y,\n ]"},{'id': '194', 'type': 'subscript', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'arcs'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '197', 'type': 'subscript', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'prom'},{'id': '199', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '200', 'type': 'subscript', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'sig'},{'id': '202', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '204', 'type': 'return_statement', 'children': ['205']},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'res'} | def getList(self, aspList):
objects = self._elements(self.SIG_OBJECTS, self.N, [0])
houses = self._elements(self.SIG_HOUSES, self.N, [0])
angles = self._elements(self.SIG_ANGLES, self.N, [0])
significators = objects + houses + angles
objects = self._elements(self.SIG_OBJECTS, self.N, aspList)
terms = self._terms()
antiscias = self._elements(self.SIG_OBJECTS, self.A, [0])
cantiscias = self._elements(self.SIG_OBJECTS, self.C, [0])
promissors = objects + terms + antiscias + cantiscias
res = []
for prom in promissors:
for sig in significators:
if (prom['id'] == sig['id']):
continue
arcs = self._arc(prom, sig)
for (x,y) in [('arcm', 'M'), ('arcz', 'Z')]:
arc = arcs[x]
if 0 < arc < self.MAX_ARC:
res.append([
arcs[x],
prom['id'],
sig['id'],
y,
])
return sorted(res) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'knt2mlt'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '5', 'type': 'block', 'children': ['6', '15', '27', '31', '35', '76']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'atleast_1d'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '15', 'type': 'if_statement', 'children': ['16', '21']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '20'], 'value': '>'},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '20', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'string', 'children': [], 'value': '"t must be a list or a rank-1 array"'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '30', 'type': 'list', 'children': [], 'value': '[]'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'for_statement', 'children': ['36', '37', '45']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'subscript', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '44', 'type': 'integer', 'children': [], 'value': '0'},{'id': '45', 'type': 'block', 'children': ['46', '69']},{'id': '46', 'type': 'if_statement', 'children': ['47', '52', '63']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '51'], 'value': '!='},{'id': '48', 'type': 'subscript', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '52', 'type': 'block', 'children': ['53', '59']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '62', 'type': 'integer', 'children': [], 'value': '0'},{'id': '63', 'type': 'else_clause', 'children': ['64']},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'augmented_assignment', 'children': ['67', '68'], 'value': '+='},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '68', 'type': 'integer', 'children': [], 'value': '1'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '76', 'type': 'return_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'out'} | def knt2mlt(t):
t = np.atleast_1d(t)
if t.ndim > 1:
raise ValueError("t must be a list or a rank-1 array")
out = []
e = None
for k in range(t.shape[0]):
if t[k] != e:
e = t[k]
count = 0
else:
count += 1
out.append(count)
return np.array( out ) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_gallery'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'section'},{'id': '7', 'type': 'string', 'children': [], 'value': "'hot'"},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '10', 'type': 'string', 'children': [], 'value': "'viral'"},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'window'},{'id': '13', 'type': 'string', 'children': [], 'value': "'day'"},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'show_viral'},{'id': '16', 'type': 'True', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'block', 'children': ['21', '41', '53']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '24', 'type': '()', 'children': ['25']},{'id': '25', 'type': 'binary_operator', 'children': ['26', '29'], 'value': '+'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': '_base_url'},{'id': '29', 'type': 'call', 'children': ['30', '35']},{'id': '30', 'type': 'attribute', 'children': ['31', '34']},{'id': '31', 'type': 'concatenated_string', 'children': ['32', '33']},{'id': '32', 'type': 'string', 'children': [], 'value': '"/3/gallery/{}/{}/{}/{}?showViral="'},{'id': '33', 'type': 'string', 'children': [], 'value': '"{}"'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37', '38', '39', '40']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'section'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'window'},{'id': '39', 'type': 'string', 'children': [], 'value': "'{}'"},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'show_viral'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': '_send_request'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '53', 'type': 'return_statement', 'children': ['54']},{'id': '54', 'type': 'list_comprehension', 'children': ['55', '60']},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': '_get_album_or_image'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'thing'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'for_in_clause', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'thing'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'resp'} | def get_gallery(self, section='hot', sort='viral', window='day',
show_viral=True, limit=None):
url = (self._base_url + "/3/gallery/{}/{}/{}/{}?showViral="
"{}".format(section, sort, window, '{}', show_viral))
resp = self._send_request(url, limit=limit)
return [_get_album_or_image(thing, self) for thing in resp] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_neighbors'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'neighbors'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'coords'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'I'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'source_files'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sides'},{'id': '10', 'type': 'block', 'children': ['11', '85']},{'id': '11', 'type': 'for_statement', 'children': ['12', '15', '19']},{'id': '12', 'type': 'pattern_list', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'c1'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'coords'},{'id': '19', 'type': 'block', 'children': ['20', '28', '40']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'me'},{'id': '23', 'type': 'subscript', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'source_files'},{'id': '25', 'type': 'subscript', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'I'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '28', 'type': 'if_statement', 'children': ['29', '38']},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '37'], 'value': '!='},{'id': '30', 'type': 'subscript', 'children': ['31', '34']},{'id': '31', 'type': 'subscript', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'neighbors'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'me'},{'id': '34', 'type': 'subscript', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'sides'},{'id': '36', 'type': 'integer', 'children': [], 'value': '0'},{'id': '37', 'type': 'string', 'children': [], 'value': "''"},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'continue_statement', 'children': []},{'id': '40', 'type': 'for_statement', 'children': ['41', '44', '48']},{'id': '41', 'type': 'pattern_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'c2'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'coords'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'if_statement', 'children': ['50', '55']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'c1'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'c2'},{'id': '55', 'type': 'block', 'children': ['56', '64', '74', '84']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'neigh'},{'id': '59', 'type': 'subscript', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'source_files'},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'I'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '73']},{'id': '66', 'type': 'subscript', 'children': ['67', '70']},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'neighbors'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'me'},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'sides'},{'id': '72', 'type': 'integer', 'children': [], 'value': '0'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'neigh'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '83']},{'id': '76', 'type': 'subscript', 'children': ['77', '80']},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'neighbors'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'neigh'},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'sides'},{'id': '82', 'type': 'integer', 'children': [], 'value': '1'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'me'},{'id': '84', 'type': 'break_statement', 'children': []},{'id': '85', 'type': 'return_statement', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'neighbors'} | def find_neighbors(neighbors, coords, I, source_files, f, sides):
for i, c1 in enumerate(coords):
me = source_files[I[i]]
if neighbors[me][sides[0]] != '':
continue
for j, c2 in enumerate(coords):
if f(c1, c2):
neigh = source_files[I[j]]
neighbors[me][sides[0]] = neigh
neighbors[neigh][sides[1]] = me
break
return neighbors |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sortrows'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '7', 'type': 'integer', 'children': [], 'value': '0'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'index_out'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'recurse'},{'id': '13', 'type': 'True', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '28', '36', '139']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'I'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'subscript', 'children': ['24', '25', '27']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '25', 'type': 'slice', 'children': ['26']},{'id': '26', 'type': 'colon', 'children': []},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '31', 'type': 'subscript', 'children': ['32', '33', '34']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'I'},{'id': '34', 'type': 'slice', 'children': ['35']},{'id': '35', 'type': 'colon', 'children': []},{'id': '36', 'type': 'if_statement', 'children': ['37', '50']},{'id': '37', 'type': 'binary_operator', 'children': ['38', '39'], 'value': '&'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'recurse'},{'id': '39', 'type': '()', 'children': ['40']},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '47'], 'value': '>'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '46', 'type': 'integer', 'children': [], 'value': '0'},{'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '+'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '49', 'type': 'integer', 'children': [], 'value': '1'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'for_statement', 'children': ['52', '53', '63']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'subscript', 'children': ['59', '60', '62']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '60', 'type': 'slice', 'children': ['61']},{'id': '61', 'type': 'colon', 'children': []},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '63', 'type': 'block', 'children': ['64', '74', '94', '122']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '73'], 'value': '=='},{'id': '68', 'type': 'subscript', 'children': ['69', '70', '72']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '70', 'type': 'slice', 'children': ['71']},{'id': '71', 'type': 'colon', 'children': []},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'colids'},{'id': '77', 'type': 'binary_operator', 'children': ['78', '82'], 'value': '+'},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '84', 'type': 'argument_list', 'children': ['85', '88']},{'id': '85', 'type': 'binary_operator', 'children': ['86', '87'], 'value': '+'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '87', 'type': 'integer', 'children': [], 'value': '1'},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '93', 'type': 'integer', 'children': [], 'value': '0'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '107']},{'id': '96', 'type': 'pattern_list', 'children': ['97', '106']},{'id': '97', 'type': 'subscript', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'ix_'},{'id': '103', 'type': 'argument_list', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'colids'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'I2'},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'sortrows'},{'id': '109', 'type': 'argument_list', 'children': ['110', '119', '120', '121']},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'ix_'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'colids'},{'id': '119', 'type': 'integer', 'children': [], 'value': '0'},{'id': '120', 'type': 'True', 'children': []},{'id': '121', 'type': 'True', 'children': []},{'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': 'I'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'I'},{'id': '129', 'type': 'subscript', 'children': ['130', '138']},{'id': '130', 'type': 'subscript', 'children': ['131', '137']},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'nonzero'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '137', 'type': 'integer', 'children': [], 'value': '0'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'I2'},{'id': '139', 'type': 'if_statement', 'children': ['140', '141', '146']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'index_out'},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'return_statement', 'children': ['143']},{'id': '143', 'type': 'expression_list', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'I'},{'id': '146', 'type': 'else_clause', 'children': ['147']},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'return_statement', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'a'} | def sortrows(a, i=0, index_out=False, recurse=True):
I = np.argsort(a[:, i])
a = a[I, :]
if recurse & (len(a[0]) > i + 1):
for b in np.unique(a[:, i]):
ids = a[:, i] == b
colids = range(i) + range(i+1, len(a[0]))
a[np.ix_(ids, colids)], I2 = sortrows(a[np.ix_(ids, colids)],
0, True, True)
I[ids] = I[np.nonzero(ids)[0][I2]]
if index_out:
return a, I
else:
return a |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'my_notes'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'start_index'},{'id': '7', 'type': 'integer', 'children': [], 'value': '0'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '10', 'type': 'integer', 'children': [], 'value': '100'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'get_all'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '16', 'type': 'string', 'children': [], 'value': "'loanId'"},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'sort_dir'},{'id': '19', 'type': 'string', 'children': [], 'value': "'asc'"},{'id': '20', 'type': 'block', 'children': ['21', '25', '38', '146']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'start_index'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'notes'},{'id': '28', 'type': 'dictionary', 'children': ['29', '32', '35']},{'id': '29', 'type': 'pair', 'children': ['30', '31']},{'id': '30', 'type': 'string', 'children': [], 'value': "'loans'"},{'id': '31', 'type': 'list', 'children': [], 'value': '[]'},{'id': '32', 'type': 'pair', 'children': ['33', '34']},{'id': '33', 'type': 'string', 'children': [], 'value': "'total'"},{'id': '34', 'type': 'integer', 'children': [], 'value': '0'},{'id': '35', 'type': 'pair', 'children': ['36', '37']},{'id': '36', 'type': 'string', 'children': [], 'value': "'result'"},{'id': '37', 'type': 'string', 'children': [], 'value': "'success'"},{'id': '38', 'type': 'while_statement', 'children': ['39', '40']},{'id': '39', 'type': 'True', 'children': []},{'id': '40', 'type': 'block', 'children': ['41', '60', '74', '82', '123']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '44', 'type': 'dictionary', 'children': ['45', '48', '51', '54', '57']},{'id': '45', 'type': 'pair', 'children': ['46', '47']},{'id': '46', 'type': 'string', 'children': [], 'value': "'sortBy'"},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '48', 'type': 'pair', 'children': ['49', '50']},{'id': '49', 'type': 'string', 'children': [], 'value': "'dir'"},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'sort_dir'},{'id': '51', 'type': 'pair', 'children': ['52', '53']},{'id': '52', 'type': 'string', 'children': [], 'value': "'startindex'"},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '54', 'type': 'pair', 'children': ['55', '56']},{'id': '55', 'type': 'string', 'children': [], 'value': "'pagesize'"},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '57', 'type': 'pair', 'children': ['58', '59']},{'id': '58', 'type': 'string', 'children': [], 'value': "'namespace'"},{'id': '59', 'type': 'string', 'children': [], 'value': "'/account'"},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'response'},{'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': 'session'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'post'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'string', 'children': [], 'value': "'/account/loansAj.action'"},{'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'json_response'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '81', 'type': 'argument_list', 'children': []},{'id': '82', 'type': 'if_statement', 'children': ['83', '91', '112']},{'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': 'session'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'json_success'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'json_response'},{'id': '91', 'type': 'block', 'children': ['92', '102']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'augmented_assignment', 'children': ['94', '97'], 'value': '+='},{'id': '94', 'type': 'subscript', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'notes'},{'id': '96', 'type': 'string', 'children': [], 'value': "'loans'"},{'id': '97', 'type': 'subscript', 'children': ['98', '101']},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'json_response'},{'id': '100', 'type': 'string', 'children': [], 'value': "'searchresult'"},{'id': '101', 'type': 'string', 'children': [], 'value': "'loans'"},{'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': 'notes'},{'id': '106', 'type': 'string', 'children': [], 'value': "'total'"},{'id': '107', 'type': 'subscript', 'children': ['108', '111']},{'id': '108', 'type': 'subscript', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'json_response'},{'id': '110', 'type': 'string', 'children': [], 'value': "'searchresult'"},{'id': '111', 'type': 'string', 'children': [], 'value': "'totalRecords'"},{'id': '112', 'type': 'else_clause', 'children': ['113']},{'id': '113', 'type': 'block', 'children': ['114', '122']},{'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': 'notes'},{'id': '118', 'type': 'string', 'children': [], 'value': "'result'"},{'id': '119', 'type': 'subscript', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'json_response'},{'id': '121', 'type': 'string', 'children': [], 'value': "'result'"},{'id': '122', 'type': 'break_statement', 'children': []},{'id': '123', 'type': 'if_statement', 'children': ['124', '138', '143']},{'id': '124', 'type': 'boolean_operator', 'children': ['125', '128'], 'value': 'and'},{'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': 'is'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'get_all'},{'id': '127', 'type': 'True', 'children': []},{'id': '128', 'type': 'comparison_operator', 'children': ['129', '135'], 'value': '<'},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'subscript', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'notes'},{'id': '134', 'type': 'string', 'children': [], 'value': "'loans'"},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'notes'},{'id': '137', 'type': 'string', 'children': [], 'value': "'total'"},{'id': '138', 'type': 'block', 'children': ['139']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'augmented_assignment', 'children': ['141', '142'], 'value': '+='},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '143', 'type': 'else_clause', 'children': ['144']},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'break_statement', 'children': []},{'id': '146', 'type': 'return_statement', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'notes'} | def my_notes(self, start_index=0, limit=100, get_all=False, sort_by='loanId', sort_dir='asc'):
index = start_index
notes = {
'loans': [],
'total': 0,
'result': 'success'
}
while True:
payload = {
'sortBy': sort_by,
'dir': sort_dir,
'startindex': index,
'pagesize': limit,
'namespace': '/account'
}
response = self.session.post('/account/loansAj.action', data=payload)
json_response = response.json()
if self.session.json_success(json_response):
notes['loans'] += json_response['searchresult']['loans']
notes['total'] = json_response['searchresult']['totalRecords']
else:
notes['result'] = json_response['result']
break
if get_all is True and len(notes['loans']) < notes['total']:
index += limit
else:
break
return notes |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'blacken'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '5', 'type': 'block', 'children': ['6', '35', '53', '63', '75']},{'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': 'PYTHON'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'string', 'children': [], 'value': '"3.6"'},{'id': '14', 'type': 'block', 'children': ['15', '24', '34']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'string', 'children': [], 'value': '"Not blackening, since Python {} != Python 3.6"'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'PYTHON'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '34', 'type': 'return_statement', 'children': []},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '38', 'type': 'call', 'children': ['39', '50']},{'id': '39', 'type': 'attribute', 'children': ['40', '49']},{'id': '40', 'type': 'call', 'children': ['41', '46']},{'id': '41', 'type': 'attribute', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48']},{'id': '47', 'type': 'string', 'children': [], 'value': '"travis"'},{'id': '48', 'type': 'dictionary', 'children': []},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52']},{'id': '51', 'type': 'string', 'children': [], 'value': '"black"'},{'id': '52', 'type': 'dictionary', 'children': []},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '60', 'type': 'argument_list', 'children': ['61', '62']},{'id': '61', 'type': 'string', 'children': [], 'value': '"version"'},{'id': '62', 'type': 'string', 'children': [], 'value': '"18.5b0"'},{'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': 'c'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'string', 'children': [], 'value': '"pip install black=={}"'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'checks'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'blacken'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82', '85']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '84', 'type': 'True', 'children': []},{'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '87', 'type': 'True', 'children': []} | def blacken(c):
if not PYTHON.startswith("3.6"):
msg = "Not blackening, since Python {} != Python 3.6".format(PYTHON)
print(msg, file=sys.stderr)
return
config = c.config.get("travis", {}).get("black", {})
version = config.get("version", "18.5b0")
c.run("pip install black=={}".format(version))
checks.blacken(c, check=True, diff=True) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_versions_from_changelog'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'changelog'},{'id': '5', 'type': 'block', 'children': ['6', '24']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'versions'},{'id': '9', 'type': 'list_comprehension', 'children': ['10', '14', '17']},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'Version'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '14', 'type': 'for_in_clause', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'changelog'},{'id': '17', 'type': 'if_clause', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'BUGFIX_RELEASE_RE'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'versions'} | def _versions_from_changelog(changelog):
versions = [Version(x) for x in changelog if BUGFIX_RELEASE_RE.match(x)]
return sorted(versions) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_tags'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '5', 'type': 'block', 'children': ['6', '10', '49']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'tags_'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'for_statement', 'children': ['11', '12', '32']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'tagstr'},{'id': '12', 'type': 'call', 'children': ['13', '30']},{'id': '13', 'type': 'attribute', 'children': ['14', '29']},{'id': '14', 'type': 'call', 'children': ['15', '28']},{'id': '15', 'type': 'attribute', 'children': ['16', '27']},{'id': '16', 'type': 'attribute', 'children': ['17', '26']},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '21', 'type': 'argument_list', 'children': ['22', '23']},{'id': '22', 'type': 'string', 'children': [], 'value': '"git tag"'},{'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'hide'},{'id': '25', 'type': 'True', 'children': []},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '28', 'type': 'argument_list', 'children': []},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'try_statement', 'children': ['34', '45']},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'tags_'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'Version'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'tagstr'},{'id': '45', 'type': 'except_clause', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'pass_statement', 'children': []},{'id': '49', 'type': 'return_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'tags_'} | def _get_tags(c):
tags_ = []
for tagstr in c.run("git tag", hide=True).stdout.strip().split("\n"):
try:
tags_.append(Version(tagstr))
except ValueError:
pass
return sorted(tags_) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sortForSameExpTime'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'expTimes'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'img_paths'},{'id': '6', 'type': 'block', 'children': ['7', '9', '13', '43', '57']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'string', 'children': [], 'value': "'''\r\n return image paths sorted for same exposure time\r\n '''"},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '12', 'type': 'dictionary', 'children': []},{'id': '13', 'type': 'for_statement', 'children': ['14', '17', '22']},{'id': '14', 'type': 'pattern_list', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'expTimes'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'img_paths'},{'id': '22', 'type': 'block', 'children': ['23', '34']},{'id': '23', 'type': 'if_statement', 'children': ['24', '27']},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'not'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '33']},{'id': '30', 'type': 'subscript', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '33', 'type': 'list', 'children': [], 'value': '[]'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '41']},{'id': '36', 'type': 'attribute', 'children': ['37', '40']},{'id': '37', 'type': 'subscript', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'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': 'd'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '56', 'type': 'argument_list', 'children': []},{'id': '57', 'type': 'return_statement', 'children': ['58']},{'id': '58', 'type': 'expression_list', 'children': ['59', '67']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '66', 'type': 'argument_list', 'children': []},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '74', 'type': 'argument_list', 'children': []} | def sortForSameExpTime(expTimes, img_paths):
'''
return image paths sorted for same exposure time
'''
d = {}
for e, i in zip(expTimes, img_paths):
if e not in d:
d[e] = []
d[e].append(i)
d = OrderedDict(sorted(d.items()))
return list(d.keys()), list(d.values()) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'actionnames'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '53']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'actions'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'for_statement', 'children': ['11', '12', '22']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'service_name'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'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': 'services'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '21', 'type': 'argument_list', 'children': []},{'id': '22', 'type': 'block', 'children': ['23', '37']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'action_names'},{'id': '26', 'type': 'call', 'children': ['27', '36']},{'id': '27', 'type': 'attribute', 'children': ['28', '35']},{'id': '28', 'type': 'attribute', 'children': ['29', '34']},{'id': '29', 'type': 'subscript', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'services'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'service_name'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'actions'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '36', 'type': 'argument_list', 'children': []},{'id': '37', 'type': 'for_statement', 'children': ['38', '39', '43']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'action_name'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'action_names'},{'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': 'actions'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'tuple', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'service_name'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'action_name'},{'id': '53', 'type': 'return_statement', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'actions'} | def actionnames(self):
actions = []
for service_name in sorted(self.services.keys()):
action_names = self.services[service_name].actions.keys()
for action_name in sorted(action_names):
actions.append((service_name, action_name))
return actions |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'lookup_field_orderable'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'try_statement', 'children': ['8', '22']},{'id': '8', 'type': 'block', 'children': ['9', '20']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'call', 'children': ['11', '18']},{'id': '11', 'type': 'attribute', 'children': ['12', '17']},{'id': '12', 'type': 'attribute', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '16', 'type': 'identifier', 'children': [], 'value': '_meta'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'get_field_by_name'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '20', 'type': 'return_statement', 'children': ['21']},{'id': '21', 'type': 'True', 'children': []},{'id': '22', 'type': 'except_clause', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'return_statement', 'children': ['26']},{'id': '26', 'type': 'False', 'children': []} | def lookup_field_orderable(self, field):
try:
self.model._meta.get_field_by_name(field)
return True
except Exception:
return False |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'run'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'temp_folder'},{'id': '6', 'type': 'block', 'children': ['7', '17', '24']},{'id': '7', 'type': 'try_statement', 'children': ['8', '12']},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'import_statement', 'children': ['10']},{'id': '10', 'type': 'dotted_name', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'isort'},{'id': '12', 'type': 'except_clause', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'ImportError'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'return_statement', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'NO_ISORT_MSG'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'py_files'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'filter_python_files'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '42']},{'id': '26', 'type': 'attribute', 'children': ['27', '41']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'bash'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'string', 'children': [], 'value': "'isort -df --quiet {0}'"},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'string', 'children': [], 'value': "' '"},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'py_files'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '42', 'type': 'argument_list', 'children': []} | def run(files, temp_folder):
try:
import isort
except ImportError:
return NO_ISORT_MSG
py_files = filter_python_files(files)
return bash('isort -df --quiet {0}'.format(' '.join(py_files))).value() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'keys'},{'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': 'key'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '33']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ks'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '17', 'type': 'argument_list', 'children': ['18', '27', '30']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '33', 'type': 'return_statement', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'ks'} | def keys(self, key=None, reverse=False):
ks = sorted(list(dict.keys(self)), key=key, reverse=reverse)
return ks |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'lazy_map'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data_processor'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'data_generator'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'n_cpus'},{'id': '8', 'type': 'integer', 'children': [], 'value': '1'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'stepsize'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '40', '49', '53', '98']},{'id': '13', 'type': 'if_statement', 'children': ['14', '16', '25']},{'id': '14', 'type': 'not_operator', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'n_cpus'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'n_cpus'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'mp'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'cpu_count'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'elif_clause', 'children': ['26', '29']},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': '<'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'n_cpus'},{'id': '28', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'n_cpus'},{'id': '33', 'type': 'binary_operator', 'children': ['34', '39'], 'value': '-'},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'mp'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'cpu_count'},{'id': '38', 'type': 'argument_list', 'children': []},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'n_cpus'},{'id': '40', 'type': 'if_statement', 'children': ['41', '44']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'is'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'stepsize'},{'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': 'stepsize'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'n_cpus'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '52', 'type': 'list', 'children': [], 'value': '[]'},{'id': '53', 'type': 'with_statement', 'children': ['54', '67']},{'id': '54', 'type': 'with_clause', 'children': ['55']},{'id': '55', 'type': 'with_item', 'children': ['56']},{'id': '56', 'type': 'as_pattern', 'children': ['57', '65']},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'mp'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'Pool'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'processes'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'n_cpus'},{'id': '65', 'type': 'as_pattern_target', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'while_statement', 'children': ['69', '70']},{'id': '69', 'type': 'True', 'children': []},{'id': '70', 'type': 'block', 'children': ['71', '85']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'data_processor'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'islice'},{'id': '82', 'type': 'argument_list', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'data_generator'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'stepsize'},{'id': '85', 'type': 'if_statement', 'children': ['86', '87', '95']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '95', 'type': 'else_clause', 'children': ['96']},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'break_statement', 'children': []},{'id': '98', 'type': 'return_statement', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'results'} | def lazy_map(data_processor, data_generator, n_cpus=1, stepsize=None):
if not n_cpus:
n_cpus = mp.cpu_count()
elif n_cpus < 0:
n_cpus = mp.cpu_count() - n_cpus
if stepsize is None:
stepsize = n_cpus
results = []
with mp.Pool(processes=n_cpus) as p:
while True:
r = p.map(data_processor, islice(data_generator, stepsize))
if r:
results.extend(r)
else:
break
return results |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'lazy_imap'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data_processor'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'data_generator'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'n_cpus'},{'id': '8', 'type': 'integer', 'children': [], 'value': '1'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'stepsize'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '40', '49']},{'id': '13', 'type': 'if_statement', 'children': ['14', '16', '25']},{'id': '14', 'type': 'not_operator', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'n_cpus'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'n_cpus'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'mp'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'cpu_count'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'elif_clause', 'children': ['26', '29']},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': '<'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'n_cpus'},{'id': '28', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'n_cpus'},{'id': '33', 'type': 'binary_operator', 'children': ['34', '39'], 'value': '-'},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'mp'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'cpu_count'},{'id': '38', 'type': 'argument_list', 'children': []},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'n_cpus'},{'id': '40', 'type': 'if_statement', 'children': ['41', '44']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'is'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'stepsize'},{'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': 'stepsize'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'n_cpus'},{'id': '49', 'type': 'with_statement', 'children': ['50', '63']},{'id': '50', 'type': 'with_clause', 'children': ['51']},{'id': '51', 'type': 'with_item', 'children': ['52']},{'id': '52', 'type': 'as_pattern', 'children': ['53', '61']},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'mp'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'Pool'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'processes'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'n_cpus'},{'id': '61', 'type': 'as_pattern_target', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'while_statement', 'children': ['65', '66']},{'id': '65', 'type': 'True', 'children': []},{'id': '66', 'type': 'block', 'children': ['67', '81']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'data_processor'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'islice'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'data_generator'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'stepsize'},{'id': '81', 'type': 'if_statement', 'children': ['82', '83', '87']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'yield', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '87', 'type': 'else_clause', 'children': ['88']},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'break_statement', 'children': []} | def lazy_imap(data_processor, data_generator, n_cpus=1, stepsize=None):
if not n_cpus:
n_cpus = mp.cpu_count()
elif n_cpus < 0:
n_cpus = mp.cpu_count() - n_cpus
if stepsize is None:
stepsize = n_cpus
with mp.Pool(processes=n_cpus) as p:
while True:
r = p.map(data_processor, islice(data_generator, stepsize))
if r:
yield r
else:
break |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_dummy_thread'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'nsamples'},{'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '7', 'type': 'block', 'children': ['8', '18', '28', '41', '51', '64', '78', '133', '147', '166']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'seed'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'string', 'children': [], 'value': "'seed'"},{'id': '17', 'type': 'False', 'children': []},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'string', 'children': [], 'value': "'ndim'"},{'id': '27', 'type': 'integer', 'children': [], 'value': '2'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'logl_start'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'string', 'children': [], 'value': "'logl_start'"},{'id': '37', 'type': 'unary_operator', 'children': ['38'], 'value': '-'},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'inf'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'logl_range'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50']},{'id': '49', 'type': 'string', 'children': [], 'value': "'logl_range'"},{'id': '50', 'type': 'integer', 'children': [], 'value': '1'},{'id': '51', 'type': 'if_statement', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'raise_statement', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'string', 'children': [], 'value': "'Unexpected **kwargs: {0}'"},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '64', 'type': 'if_statement', 'children': ['65', '68']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': 'is'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'seed'},{'id': '67', 'type': 'False', 'children': []},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '76']},{'id': '71', 'type': 'attribute', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'seed'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'seed'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'thread'},{'id': '81', 'type': 'dictionary', 'children': ['82', '99', '108', '120']},{'id': '82', 'type': 'pair', 'children': ['83', '84']},{'id': '83', 'type': 'string', 'children': [], 'value': "'logl'"},{'id': '84', 'type': 'binary_operator', 'children': ['85', '98'], 'value': '*'},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '96']},{'id': '91', 'type': 'attribute', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'nsamples'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'logl_range'},{'id': '99', 'type': 'pair', 'children': ['100', '101']},{'id': '100', 'type': 'string', 'children': [], 'value': "'nlive_array'"},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'full'},{'id': '105', 'type': 'argument_list', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'nsamples'},{'id': '107', 'type': 'float', 'children': [], 'value': '1.'},{'id': '108', 'type': 'pair', 'children': ['109', '110']},{'id': '109', 'type': 'string', 'children': [], 'value': "'theta'"},{'id': '110', 'type': 'call', 'children': ['111', '116']},{'id': '111', 'type': 'attribute', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'tuple', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'nsamples'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '120', 'type': 'pair', 'children': ['121', '122']},{'id': '121', 'type': 'string', 'children': [], 'value': "'thread_labels'"},{'id': '122', 'type': 'call', 'children': ['123', '131']},{'id': '123', 'type': 'attribute', 'children': ['124', '130']},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'nsamples'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '133', 'type': 'if_statement', 'children': ['134', '140']},{'id': '134', 'type': 'comparison_operator', 'children': ['135', '136'], 'value': '!='},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'logl_start'},{'id': '136', 'type': 'unary_operator', 'children': ['137'], 'value': '-'},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'inf'},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'augmented_assignment', 'children': ['143', '146'], 'value': '+='},{'id': '143', 'type': 'subscript', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'thread'},{'id': '145', 'type': 'string', 'children': [], 'value': "'logl'"},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'logl_start'},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '152']},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'thread'},{'id': '151', 'type': 'string', 'children': [], 'value': "'thread_min_max'"},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'list', 'children': ['158'], 'value': "[[logl_start, thread['logl'][-1]]]"},{'id': '158', 'type': 'list', 'children': ['159', '160'], 'value': "[logl_start, thread['logl'][-1]]"},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'logl_start'},{'id': '160', 'type': 'subscript', 'children': ['161', '164']},{'id': '161', 'type': 'subscript', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'thread'},{'id': '163', 'type': 'string', 'children': [], 'value': "'logl'"},{'id': '164', 'type': 'unary_operator', 'children': ['165'], 'value': '-'},{'id': '165', 'type': 'integer', 'children': [], 'value': '1'},{'id': '166', 'type': 'return_statement', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'thread'} | def get_dummy_thread(nsamples, **kwargs):
seed = kwargs.pop('seed', False)
ndim = kwargs.pop('ndim', 2)
logl_start = kwargs.pop('logl_start', -np.inf)
logl_range = kwargs.pop('logl_range', 1)
if kwargs:
raise TypeError('Unexpected **kwargs: {0}'.format(kwargs))
if seed is not False:
np.random.seed(seed)
thread = {'logl': np.sort(np.random.random(nsamples)) * logl_range,
'nlive_array': np.full(nsamples, 1.),
'theta': np.random.random((nsamples, ndim)),
'thread_labels': np.zeros(nsamples).astype(int)}
if logl_start != -np.inf:
thread['logl'] += logl_start
thread['thread_min_max'] = np.asarray([[logl_start, thread['logl'][-1]]])
return thread |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.