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', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'write_tree_from_cache'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'odb'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sl'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'si'},{'id': '9', 'type': 'integer', 'children': [], 'value': '0'},{'id': '10', 'type': 'block', 'children': ['11', '15', '21', '27', '33', '190', '196', '204', '211', '232']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'tree_items'},{'id': '14', 'type': 'list', 'children': [], 'value': '[]'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'tree_items_append'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'tree_items'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'ci'},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'sl'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'sl'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '33', 'type': 'while_statement', 'children': ['34', '37']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': '<'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'ci'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '37', 'type': 'block', 'children': ['38', '44', '56', '60', '72']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'ci'},{'id': '44', 'type': 'if_statement', 'children': ['45', '50']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '49'], 'value': '!='},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'stage'},{'id': '49', 'type': 'integer', 'children': [], 'value': '0'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'raise_statement', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'UnmergedEntriesError'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'augmented_assignment', 'children': ['58', '59'], 'value': '+='},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'ci'},{'id': '59', 'type': 'integer', 'children': [], 'value': '1'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'rbound'},{'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': 'entry'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'si'},{'id': '72', 'type': 'if_statement', 'children': ['73', '77', '96']},{'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': '=='},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'rbound'},{'id': '75', 'type': 'unary_operator', 'children': ['76'], 'value': '-'},{'id': '76', 'type': 'integer', 'children': [], 'value': '1'},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'tree_items_append'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'tuple', 'children': ['83', '86', '89']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'binsha'},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '89', 'type': 'subscript', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '93', 'type': 'slice', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'si'},{'id': '95', 'type': 'colon', 'children': []},{'id': '96', 'type': 'else_clause', 'children': ['97']},{'id': '97', 'type': 'block', 'children': ['98', '109', '113', '158', '178', '186']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '101', 'type': 'subscript', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '105', 'type': 'slice', 'children': ['106', '107', '108']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'si'},{'id': '107', 'type': 'colon', 'children': []},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'rbound'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'xi'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'ci'},{'id': '113', 'type': 'while_statement', 'children': ['114', '117']},{'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': '<'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'xi'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '117', 'type': 'block', 'children': ['118', '124', '136', '154']},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'oentry'},{'id': '121', 'type': 'subscript', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'xi'},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'orbound'},{'id': '127', 'type': 'call', 'children': ['128', '133']},{'id': '128', 'type': 'attribute', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'oentry'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '133', 'type': 'argument_list', 'children': ['134', '135']},{'id': '134', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'si'},{'id': '136', 'type': 'if_statement', 'children': ['137', '152']},{'id': '137', 'type': 'boolean_operator', 'children': ['138', '142'], 'value': 'or'},{'id': '138', 'type': 'comparison_operator', 'children': ['139', '140'], 'value': '=='},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'orbound'},{'id': '140', 'type': 'unary_operator', 'children': ['141'], 'value': '-'},{'id': '141', 'type': 'integer', 'children': [], 'value': '1'},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '151'], 'value': '!='},{'id': '143', 'type': 'subscript', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'oentry'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '147', 'type': 'slice', 'children': ['148', '149', '150']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'si'},{'id': '149', 'type': 'colon', 'children': []},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'orbound'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'break_statement', 'children': []},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'augmented_assignment', 'children': ['156', '157'], 'value': '+='},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'xi'},{'id': '157', 'type': 'integer', 'children': [], 'value': '1'},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '163']},{'id': '160', 'type': 'pattern_list', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'sha'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'tree_entry_list'},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'write_tree_from_cache'},{'id': '165', 'type': 'argument_list', 'children': ['166', '167', '168', '175']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'odb'},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'slice'},{'id': '170', 'type': 'argument_list', 'children': ['171', '174']},{'id': '171', 'type': 'binary_operator', 'children': ['172', '173'], 'value': '-'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'ci'},{'id': '173', 'type': 'integer', 'children': [], 'value': '1'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'xi'},{'id': '175', 'type': 'binary_operator', 'children': ['176', '177'], 'value': '+'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'rbound'},{'id': '177', 'type': 'integer', 'children': [], 'value': '1'},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'call', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'tree_items_append'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'tuple', 'children': ['183', '184', '185']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'sha'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'S_IFDIR'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'ci'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'xi'},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'sio'},{'id': '193', 'type': 'call', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'BytesIO'},{'id': '195', 'type': 'argument_list', 'children': []},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'call', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'tree_to_stream'},{'id': '199', 'type': 'argument_list', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'tree_items'},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'sio'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'call', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'sio'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'seek'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'integer', 'children': [], 'value': '0'},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'istream'},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'odb'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'IStream'},{'id': '221', 'type': 'argument_list', 'children': ['222', '223', '231']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'str_tree_type'},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'call', 'children': ['227', '230']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'sio'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'getvalue'},{'id': '230', 'type': 'argument_list', 'children': []},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'sio'},{'id': '232', 'type': 'return_statement', 'children': ['233']},{'id': '233', 'type': 'tuple', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'istream'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'binsha'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'tree_items'} | def write_tree_from_cache(entries, odb, sl, si=0):
tree_items = []
tree_items_append = tree_items.append
ci = sl.start
end = sl.stop
while ci < end:
entry = entries[ci]
if entry.stage != 0:
raise UnmergedEntriesError(entry)
ci += 1
rbound = entry.path.find('/', si)
if rbound == -1:
tree_items_append((entry.binsha, entry.mode, entry.path[si:]))
else:
base = entry.path[si:rbound]
xi = ci
while xi < end:
oentry = entries[xi]
orbound = oentry.path.find('/', si)
if orbound == -1 or oentry.path[si:orbound] != base:
break
xi += 1
sha, tree_entry_list = write_tree_from_cache(entries, odb, slice(ci - 1, xi), rbound + 1)
tree_items_append((sha, S_IFDIR, base))
ci = xi
sio = BytesIO()
tree_to_stream(tree_items, sio.write)
sio.seek(0)
istream = odb.store(IStream(str_tree_type, len(sio.getvalue()), sio))
return (istream.binsha, tree_items) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'select_segment'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'segs'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'segs_tips'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'segs_undecided'},{'id': '8', 'type': 'type', 'children': ['9']},{'id': '9', 'type': 'generic_type', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'Tuple'},{'id': '11', 'type': 'type_parameter', 'children': ['12', '14']},{'id': '12', 'type': 'type', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '14', 'type': 'type', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '16', 'type': 'block', 'children': ['17', '31', '49', '387', '400', '413', '427']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'scores_tips'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'tuple', 'children': ['26', '30']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'segs'},{'id': '30', 'type': 'integer', 'children': [], 'value': '4'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'allindices'},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '38', 'type': 'argument_list', 'children': ['39', '46']},{'id': '39', 'type': 'subscript', 'children': ['40', '45']},{'id': '40', 'type': 'attribute', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': '_adata'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '45', 'type': 'integer', 'children': [], 'value': '0'},{'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '49', 'type': 'for_statement', 'children': ['50', '53', '57']},{'id': '50', 'type': 'pattern_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'iseg'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'seg'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'segs'},{'id': '57', 'type': 'block', 'children': ['58', '69', '106', '110', '176', '199', '213', '227', '236', '289', '299', '316', '328', '357', '371', '378']},{'id': '58', 'type': 'if_statement', 'children': ['59', '67']},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '65'], 'value': '=='},{'id': '60', 'type': 'subscript', 'children': ['61', '64']},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'segs_tips'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'iseg'},{'id': '64', 'type': 'integer', 'children': [], 'value': '0'},{'id': '65', 'type': 'unary_operator', 'children': ['66'], 'value': '-'},{'id': '66', 'type': 'integer', 'children': [], 'value': '1'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'continue_statement', 'children': []},{'id': '69', 'type': 'if_statement', 'children': ['70', '78', '93']},{'id': '70', 'type': 'not_operator', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '73', 'type': 'argument_list', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'distances_dpt'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'OnFlySymMatrix'},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'Dseg'},{'id': '82', 'type': 'subscript', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'distances_dpt'},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'ix_'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'seg'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'seg'},{'id': '93', 'type': 'else_clause', 'children': ['94']},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'Dseg'},{'id': '98', 'type': 'call', 'children': ['99', '104']},{'id': '99', 'type': 'attribute', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'distances_dpt'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'restrict'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'seg'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'third_maximizer'},{'id': '109', 'type': 'None', 'children': []},{'id': '110', 'type': 'if_statement', 'children': ['111', '114']},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'segs_undecided'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'iseg'},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'for_statement', 'children': ['116', '117', '124']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'jseg'},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'segs'},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'if_statement', 'children': ['126', '129']},{'id': '126', 'type': 'comparison_operator', 'children': ['127', '128'], 'value': '!='},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'jseg'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'iseg'},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'for_statement', 'children': ['131', '132', '136']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'itip'},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'integer', 'children': [], 'value': '2'},{'id': '136', 'type': 'block', 'children': ['137']},{'id': '137', 'type': 'if_statement', 'children': ['138', '171']},{'id': '138', 'type': '()', 'children': ['139']},{'id': '139', 'type': 'comparison_operator', 'children': ['140', '154'], 'value': '<'},{'id': '140', 'type': 'subscript', 'children': ['141', '144', '149']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'distances_dpt'},{'id': '144', 'type': 'subscript', 'children': ['145', '148']},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'segs_tips'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'jseg'},{'id': '148', 'type': 'integer', 'children': [], 'value': '1'},{'id': '149', 'type': 'subscript', 'children': ['150', '153']},{'id': '150', 'type': 'subscript', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'segs_tips'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'iseg'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'itip'},{'id': '154', 'type': 'binary_operator', 'children': ['155', '156'], 'value': '*'},{'id': '155', 'type': 'float', 'children': [], 'value': '0.5'},{'id': '156', 'type': 'subscript', 'children': ['157', '160', '166']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'distances_dpt'},{'id': '160', 'type': 'subscript', 'children': ['161', '164']},{'id': '161', 'type': 'subscript', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'segs_tips'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'iseg'},{'id': '164', 'type': 'unary_operator', 'children': ['165'], 'value': '~'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'itip'},{'id': '166', 'type': 'subscript', 'children': ['167', '170']},{'id': '167', 'type': 'subscript', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'segs_tips'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'iseg'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'itip'},{'id': '171', 'type': 'block', 'children': ['172']},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'third_maximizer'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'itip'},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'tips'},{'id': '179', 'type': 'list_comprehension', 'children': ['180', '194']},{'id': '180', 'type': 'subscript', 'children': ['181', '193']},{'id': '181', 'type': 'subscript', 'children': ['182', '192']},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'where'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'comparison_operator', 'children': ['188', '191'], 'value': '=='},{'id': '188', 'type': 'subscript', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'allindices'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'seg'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'tip'},{'id': '192', 'type': 'integer', 'children': [], 'value': '0'},{'id': '193', 'type': 'integer', 'children': [], 'value': '0'},{'id': '194', 'type': 'for_in_clause', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'tip'},{'id': '196', 'type': 'subscript', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'segs_tips'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'iseg'},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'dseg'},{'id': '202', 'type': 'binary_operator', 'children': ['203', '208'], 'value': '+'},{'id': '203', 'type': 'subscript', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'Dseg'},{'id': '205', 'type': 'subscript', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'tips'},{'id': '207', 'type': 'integer', 'children': [], 'value': '0'},{'id': '208', 'type': 'subscript', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'Dseg'},{'id': '210', 'type': 'subscript', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'tips'},{'id': '212', 'type': 'integer', 'children': [], 'value': '1'},{'id': '213', 'type': 'if_statement', 'children': ['214', '225']},{'id': '214', 'type': 'not_operator', 'children': ['215']},{'id': '215', 'type': 'call', 'children': ['216', '224']},{'id': '216', 'type': 'attribute', 'children': ['217', '223']},{'id': '217', 'type': 'call', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'isfinite'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'dseg'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '224', 'type': 'argument_list', 'children': []},{'id': '225', 'type': 'block', 'children': ['226']},{'id': '226', 'type': 'continue_statement', 'children': []},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'assignment', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'third_tip'},{'id': '230', 'type': 'call', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'argmax'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'dseg'},{'id': '236', 'type': 'if_statement', 'children': ['237', '240']},{'id': '237', 'type': 'comparison_operator', 'children': ['238', '239'], 'value': 'is'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'third_maximizer'},{'id': '239', 'type': 'None', 'children': []},{'id': '240', 'type': 'block', 'children': ['241', '247', '256']},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'augmented_assignment', 'children': ['243', '244'], 'value': '+='},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'dseg'},{'id': '244', 'type': 'subscript', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'Dseg'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'third_tip'},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'assignment', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'fourth_tip'},{'id': '250', 'type': 'call', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'argmax'},{'id': '254', 'type': 'argument_list', 'children': ['255']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'dseg'},{'id': '256', 'type': 'if_statement', 'children': ['257', '266', '281']},{'id': '257', 'type': 'boolean_operator', 'children': ['258', '263'], 'value': 'and'},{'id': '258', 'type': 'comparison_operator', 'children': ['259', '260'], 'value': '!='},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'fourth_tip'},{'id': '260', 'type': 'subscript', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'tips'},{'id': '262', 'type': 'integer', 'children': [], 'value': '0'},{'id': '263', 'type': 'comparison_operator', 'children': ['264', '265'], 'value': '!='},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'fourth_tip'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'third_tip'},{'id': '266', 'type': 'block', 'children': ['267', '273']},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'assignment', 'children': ['269', '272']},{'id': '269', 'type': 'subscript', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'tips'},{'id': '271', 'type': 'integer', 'children': [], 'value': '1'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'fourth_tip'},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'augmented_assignment', 'children': ['275', '276'], 'value': '-='},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'dseg'},{'id': '276', 'type': 'subscript', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'Dseg'},{'id': '278', 'type': 'subscript', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'tips'},{'id': '280', 'type': 'integer', 'children': [], 'value': '1'},{'id': '281', 'type': 'else_clause', 'children': ['282']},{'id': '282', 'type': 'block', 'children': ['283']},{'id': '283', 'type': 'expression_statement', 'children': ['284']},{'id': '284', 'type': 'augmented_assignment', 'children': ['285', '286'], 'value': '-='},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'dseg'},{'id': '286', 'type': 'subscript', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'Dseg'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'third_tip'},{'id': '289', 'type': 'expression_statement', 'children': ['290']},{'id': '290', 'type': 'assignment', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'tips3'},{'id': '292', 'type': 'call', 'children': ['293', '296']},{'id': '293', 'type': 'attribute', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '296', 'type': 'argument_list', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'tips'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'third_tip'},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'assignment', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '302', 'type': 'binary_operator', 'children': ['303', '308'], 'value': '/'},{'id': '303', 'type': 'subscript', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'dseg'},{'id': '305', 'type': 'subscript', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'tips3'},{'id': '307', 'type': 'integer', 'children': [], 'value': '2'},{'id': '308', 'type': 'subscript', 'children': ['309', '310', '313']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'Dseg'},{'id': '310', 'type': 'subscript', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'tips3'},{'id': '312', 'type': 'integer', 'children': [], 'value': '0'},{'id': '313', 'type': 'subscript', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'tips3'},{'id': '315', 'type': 'integer', 'children': [], 'value': '1'},{'id': '316', 'type': 'expression_statement', 'children': ['317']},{'id': '317', 'type': 'assignment', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '319', 'type': 'conditional_expression', 'children': ['320', '324', '327'], 'value': 'if'},{'id': '320', 'type': 'call', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '322', 'type': 'argument_list', 'children': ['323']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'seg'},{'id': '324', 'type': 'attribute', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'choose_largest_segment'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '328', 'type': 'expression_statement', 'children': ['329']},{'id': '329', 'type': 'call', 'children': ['330', '333']},{'id': '330', 'type': 'attribute', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'logg'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '333', 'type': 'argument_list', 'children': ['334', '335', '336', '337', '338', '339', '343', '354']},{'id': '334', 'type': 'string', 'children': [], 'value': "' group'"},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'iseg'},{'id': '336', 'type': 'string', 'children': [], 'value': "'score'"},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '338', 'type': 'string', 'children': [], 'value': "'n_points'"},{'id': '339', 'type': 'call', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '341', 'type': 'argument_list', 'children': ['342']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'seg'},{'id': '343', 'type': 'conditional_expression', 'children': ['344', '345', '353'], 'value': 'if'},{'id': '344', 'type': 'string', 'children': [], 'value': "'(too small)'"},{'id': '345', 'type': 'comparison_operator', 'children': ['346', '350'], 'value': '<'},{'id': '346', 'type': 'call', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '348', 'type': 'argument_list', 'children': ['349']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'seg'},{'id': '350', 'type': 'attribute', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'min_group_size'},{'id': '353', 'type': 'string', 'children': [], 'value': "''"},{'id': '354', 'type': 'keyword_argument', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '356', 'type': 'integer', 'children': [], 'value': '4'},{'id': '357', 'type': 'if_statement', 'children': ['358', '366']},{'id': '358', 'type': 'comparison_operator', 'children': ['359', '363'], 'value': '<='},{'id': '359', 'type': 'call', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '361', 'type': 'argument_list', 'children': ['362']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'seg'},{'id': '363', 'type': 'attribute', 'children': ['364', '365']},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'min_group_size'},{'id': '366', 'type': 'block', 'children': ['367']},{'id': '367', 'type': 'expression_statement', 'children': ['368']},{'id': '368', 'type': 'assignment', 'children': ['369', '370']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '370', 'type': 'integer', 'children': [], 'value': '0'},{'id': '371', 'type': 'expression_statement', 'children': ['372']},{'id': '372', 'type': 'assignment', 'children': ['373', '377']},{'id': '373', 'type': 'subscript', 'children': ['374', '375', '376']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'scores_tips'},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'iseg'},{'id': '376', 'type': 'integer', 'children': [], 'value': '0'},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '378', 'type': 'expression_statement', 'children': ['379']},{'id': '379', 'type': 'assignment', 'children': ['380', '386']},{'id': '380', 'type': 'subscript', 'children': ['381', '382', '383']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'scores_tips'},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'iseg'},{'id': '383', 'type': 'slice', 'children': ['384', '385']},{'id': '384', 'type': 'integer', 'children': [], 'value': '1'},{'id': '385', 'type': 'colon', 'children': []},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'tips3'},{'id': '387', 'type': 'expression_statement', 'children': ['388']},{'id': '388', 'type': 'assignment', 'children': ['389', '390']},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'iseg'},{'id': '390', 'type': 'call', 'children': ['391', '394']},{'id': '391', 'type': 'attribute', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'argmax'},{'id': '394', 'type': 'argument_list', 'children': ['395']},{'id': '395', 'type': 'subscript', 'children': ['396', '397', '399']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'scores_tips'},{'id': '397', 'type': 'slice', 'children': ['398']},{'id': '398', 'type': 'colon', 'children': []},{'id': '399', 'type': 'integer', 'children': [], 'value': '0'},{'id': '400', 'type': 'if_statement', 'children': ['401', '407']},{'id': '401', 'type': 'comparison_operator', 'children': ['402', '406'], 'value': '=='},{'id': '402', 'type': 'subscript', 'children': ['403', '404', '405']},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'scores_tips'},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'iseg'},{'id': '405', 'type': 'integer', 'children': [], 'value': '0'},{'id': '406', 'type': 'integer', 'children': [], 'value': '0'},{'id': '407', 'type': 'block', 'children': ['408']},{'id': '408', 'type': 'return_statement', 'children': ['409']},{'id': '409', 'type': 'expression_list', 'children': ['410', '412']},{'id': '410', 'type': 'unary_operator', 'children': ['411'], 'value': '-'},{'id': '411', 'type': 'integer', 'children': [], 'value': '1'},{'id': '412', 'type': 'None', 'children': []},{'id': '413', 'type': 'expression_statement', 'children': ['414']},{'id': '414', 'type': 'assignment', 'children': ['415', '416']},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'tips3'},{'id': '416', 'type': 'call', 'children': ['417', '425']},{'id': '417', 'type': 'attribute', 'children': ['418', '424']},{'id': '418', 'type': 'subscript', 'children': ['419', '420', '421']},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'scores_tips'},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'iseg'},{'id': '421', 'type': 'slice', 'children': ['422', '423']},{'id': '422', 'type': 'integer', 'children': [], 'value': '1'},{'id': '423', 'type': 'colon', 'children': []},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '425', 'type': 'argument_list', 'children': ['426']},{'id': '426', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '427', 'type': 'return_statement', 'children': ['428']},{'id': '428', 'type': 'expression_list', 'children': ['429', '430']},{'id': '429', 'type': 'identifier', 'children': [], 'value': 'iseg'},{'id': '430', 'type': 'identifier', 'children': [], 'value': 'tips3'} | def select_segment(self, segs, segs_tips, segs_undecided) -> Tuple[int, int]:
scores_tips = np.zeros((len(segs), 4))
allindices = np.arange(self._adata.shape[0], dtype=int)
for iseg, seg in enumerate(segs):
if segs_tips[iseg][0] == -1: continue
if not isinstance(self.distances_dpt, OnFlySymMatrix):
Dseg = self.distances_dpt[np.ix_(seg, seg)]
else:
Dseg = self.distances_dpt.restrict(seg)
third_maximizer = None
if segs_undecided[iseg]:
for jseg in range(len(segs)):
if jseg != iseg:
for itip in range(2):
if (self.distances_dpt[segs_tips[jseg][1], segs_tips[iseg][itip]]
< 0.5 * self.distances_dpt[segs_tips[iseg][~itip], segs_tips[iseg][itip]]):
third_maximizer = itip
tips = [np.where(allindices[seg] == tip)[0][0]
for tip in segs_tips[iseg]]
dseg = Dseg[tips[0]] + Dseg[tips[1]]
if not np.isfinite(dseg).any():
continue
third_tip = np.argmax(dseg)
if third_maximizer is not None:
dseg += Dseg[third_tip]
fourth_tip = np.argmax(dseg)
if fourth_tip != tips[0] and fourth_tip != third_tip:
tips[1] = fourth_tip
dseg -= Dseg[tips[1]]
else:
dseg -= Dseg[third_tip]
tips3 = np.append(tips, third_tip)
score = dseg[tips3[2]] / Dseg[tips3[0], tips3[1]]
score = len(seg) if self.choose_largest_segment else score
logg.m(' group', iseg, 'score', score, 'n_points', len(seg),
'(too small)' if len(seg) < self.min_group_size else '', v=4)
if len(seg) <= self.min_group_size: score = 0
scores_tips[iseg, 0] = score
scores_tips[iseg, 1:] = tips3
iseg = np.argmax(scores_tips[:, 0])
if scores_tips[iseg, 0] == 0: return -1, None
tips3 = scores_tips[iseg, 1:].astype(int)
return iseg, tips3 |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'unique_categories'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '5', 'type': 'block', 'children': ['6', '15', '32', '54']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'categories'},{'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': 'unique'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'categories'},{'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': 'setdiff1d'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'categories_to_ignore'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'natsorted'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '46', 'type': 'lambda', 'children': ['47', '49']},{'id': '47', 'type': 'lambda_parameters', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '53', 'type': 'argument_list', 'children': []},{'id': '54', 'type': 'return_statement', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'categories'} | def unique_categories(categories):
categories = np.unique(categories)
categories = np.setdiff1d(categories, np.array(settings.categories_to_ignore))
categories = np.array(natsorted(categories, key=lambda v: v.upper()))
return categories |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_one_and_delete'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'projection'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'dictionary_splat_pattern', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '17', 'type': 'block', 'children': ['18', '24']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '23']},{'id': '20', 'type': 'subscript', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '22', 'type': 'string', 'children': [], 'value': "'remove'"},{'id': '23', 'type': 'True', 'children': []},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': '__find_and_modify'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31', '32', '33', '36']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'projection'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '36', 'type': 'dictionary_splat', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'kwargs'} | def find_one_and_delete(self, filter,
projection=None, sort=None, session=None, **kwargs):
kwargs['remove'] = True
return self.__find_and_modify(filter, projection, sort,
session=session, **kwargs) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '5', 'type': 'block', 'children': ['6', '13', '23', '53']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'new_lines'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'parse_block'},{'id': '18', 'type': 'argument_list', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '22', 'type': 'True', 'children': []},{'id': '23', 'type': 'for_statement', 'children': ['24', '25', '35']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '27', 'type': 'argument_list', 'children': ['28', '32']},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'parse_blocks'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'first_key'},{'id': '35', 'type': 'block', 'children': ['36', '46']},{'id': '36', 'type': 'if_statement', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'new_lines'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'new_lines'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'string', 'children': [], 'value': "''"},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'new_lines'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '53', 'type': 'return_statement', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'new_lines'} | def sort(lines):
lines = list(lines)
new_lines = parse_block(lines, header=True)
for block in sorted(parse_blocks(lines), key=first_key):
if new_lines:
new_lines.append('')
new_lines.extend(block)
return new_lines |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'first_key'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'for_statement', 'children': ['7', '8', '9', '38']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '9', 'type': 'block', 'children': ['10', '36']},{'id': '10', 'type': 'if_statement', 'children': ['11', '14', '29']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '14', 'type': 'ERROR', 'children': ['15', '16', '17']},{'id': '15', 'type': 'ERROR', 'children': []},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'continue'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '19', 'type': 'generator_expression', 'children': ['20', '26']},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'quote'},{'id': '26', 'type': 'for_in_clause', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'quote'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'QUOTES'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'return_statement', 'children': ['31']},{'id': '31', 'type': 'subscript', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '33', 'type': 'slice', 'children': ['34', '35']},{'id': '34', 'type': 'integer', 'children': [], 'value': '1'},{'id': '35', 'type': 'colon', 'children': []},{'id': '36', 'type': 'return_statement', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '38', 'type': 'else_clause', 'children': ['39']},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'return_statement', 'children': ['41']},{'id': '41', 'type': 'string', 'children': [], 'value': "''"} | def first_key(lines):
for line in lines:
if line.startswith('
continue
if any(line.startswith(quote) for quote in QUOTES):
return line[1:]
return line
else:
return '' |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'geoadd'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'longitude'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'latitude'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '9', 'type': 'list_splat_pattern', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '11', 'type': 'dictionary_splat_pattern', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'return_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21', '22', '23', '24', '25', '27']},{'id': '20', 'type': 'string', 'children': [], 'value': "b'GEOADD'"},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'longitude'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'latitude'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '25', 'type': 'list_splat', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '27', 'type': 'dictionary_splat', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'kwargs'} | def geoadd(self, key, longitude, latitude, member, *args, **kwargs):
return self.execute(
b'GEOADD', key, longitude, latitude, member, *args, **kwargs
) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '31']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'georadius'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '12', '13', '16', '19', '22', '25', '28']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'longitude'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'latitude'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'radius'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '11', 'type': 'string', 'children': [], 'value': "'m'"},{'id': '12', 'type': 'keyword_separator', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'with_dist'},{'id': '15', 'type': 'False', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'with_hash'},{'id': '18', 'type': 'False', 'children': []},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'with_coord'},{'id': '21', 'type': 'False', 'children': []},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'default_parameter', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'default_parameter', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '30', 'type': 'identifier', 'children': [], 'value': '_NOTSET'},{'id': '31', 'type': 'block', 'children': ['32', '45', '64', '86']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'validate_georadius_options'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39', '40', '41', '42', '43', '44']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'radius'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'with_dist'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'with_hash'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'with_coord'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'fut'},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54', '55', '56', '57', '58', '59', '61']},{'id': '53', 'type': 'string', 'children': [], 'value': "b'GEORADIUS'"},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'longitude'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'latitude'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'radius'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '59', 'type': 'list_splat', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '64', 'type': 'if_statement', 'children': ['65', '70']},{'id': '65', 'type': 'boolean_operator', 'children': ['66', '69'], 'value': 'or'},{'id': '66', 'type': 'boolean_operator', 'children': ['67', '68'], 'value': 'or'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'with_dist'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'with_hash'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'with_coord'},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'return_statement', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'wait_convert'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76', '77', '80', '83']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'fut'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'make_geomember'},{'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'with_dist'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'with_dist'},{'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'with_hash'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'with_hash'},{'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'with_coord'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'with_coord'},{'id': '86', 'type': 'return_statement', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'fut'} | def georadius(self, key, longitude, latitude, radius, unit='m', *,
with_dist=False, with_hash=False, with_coord=False,
count=None, sort=None, encoding=_NOTSET):
args = validate_georadius_options(
radius, unit, with_dist, with_hash, with_coord, count, sort
)
fut = self.execute(
b'GEORADIUS', key, longitude, latitude, radius,
unit, *args, encoding=encoding
)
if with_dist or with_hash or with_coord:
return wait_convert(fut, make_geomember,
with_dist=with_dist,
with_hash=with_hash,
with_coord=with_coord)
return fut |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '30']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'georadiusbymember'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11', '12', '15', '18', '21', '24', '27']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'radius'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '10', 'type': 'string', 'children': [], 'value': "'m'"},{'id': '11', 'type': 'keyword_separator', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'with_dist'},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'with_hash'},{'id': '17', 'type': 'False', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'with_coord'},{'id': '20', 'type': 'False', 'children': []},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'default_parameter', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_NOTSET'},{'id': '30', 'type': 'block', 'children': ['31', '44', '62', '84']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'validate_georadius_options'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38', '39', '40', '41', '42', '43']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'radius'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'with_dist'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'with_hash'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'with_coord'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'fut'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '51', 'type': 'argument_list', 'children': ['52', '53', '54', '55', '56', '57', '59']},{'id': '52', 'type': 'string', 'children': [], 'value': "b'GEORADIUSBYMEMBER'"},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'radius'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '57', 'type': 'list_splat', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '62', 'type': 'if_statement', 'children': ['63', '68']},{'id': '63', 'type': 'boolean_operator', 'children': ['64', '67'], 'value': 'or'},{'id': '64', 'type': 'boolean_operator', 'children': ['65', '66'], 'value': 'or'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'with_dist'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'with_hash'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'with_coord'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'return_statement', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'wait_convert'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74', '75', '78', '81']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'fut'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'make_geomember'},{'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'with_dist'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'with_dist'},{'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'with_hash'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'with_hash'},{'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'with_coord'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'with_coord'},{'id': '84', 'type': 'return_statement', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'fut'} | def georadiusbymember(self, key, member, radius, unit='m', *,
with_dist=False, with_hash=False, with_coord=False,
count=None, sort=None, encoding=_NOTSET):
args = validate_georadius_options(
radius, unit, with_dist, with_hash, with_coord, count, sort
)
fut = self.execute(
b'GEORADIUSBYMEMBER', key, member, radius,
unit, *args, encoding=encoding)
if with_dist or with_hash or with_coord:
return wait_convert(fut, make_geomember,
with_dist=with_dist,
with_hash=with_hash,
with_coord=with_coord)
return fut |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '8', '11', '14', '17', '20', '23']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'list_splat_pattern', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'get_patterns'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'by'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'asc'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '22', 'type': 'False', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'block', 'children': ['27', '31', '42', '58', '75', '91', '99', '110']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '30', 'type': 'list', 'children': [], 'value': '[]'},{'id': '31', 'type': 'if_statement', 'children': ['32', '35']},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'is'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'by'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'augmented_assignment', 'children': ['38', '39'], 'value': '+='},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '39', 'type': 'list', 'children': ['40', '41'], 'value': "[b'BY', by]"},{'id': '40', 'type': 'string', 'children': [], 'value': "b'BY'"},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'by'},{'id': '42', 'type': 'if_statement', 'children': ['43', '50']},{'id': '43', 'type': 'boolean_operator', 'children': ['44', '47'], 'value': 'and'},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': 'is'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '46', 'type': 'None', 'children': []},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'is'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '49', 'type': 'None', 'children': []},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'augmented_assignment', 'children': ['53', '54'], 'value': '+='},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '54', 'type': 'list', 'children': ['55', '56', '57'], 'value': "[b'LIMIT', offset, count]"},{'id': '55', 'type': 'string', 'children': [], 'value': "b'LIMIT'"},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '58', 'type': 'if_statement', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'get_patterns'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'augmented_assignment', 'children': ['63', '64'], 'value': '+='},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '66', 'type': 'argument_list', 'children': ['67', '74']},{'id': '67', 'type': 'generator_expression', 'children': ['68', '71']},{'id': '68', 'type': 'list', 'children': ['69', '70'], 'value': "[b'GET', pattern]"},{'id': '69', 'type': 'string', 'children': [], 'value': "b'GET'"},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '71', 'type': 'for_in_clause', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'get_patterns'},{'id': '74', 'type': 'list', 'children': [], 'value': '[]'},{'id': '75', 'type': 'if_statement', 'children': ['76', '79']},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': 'is'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'asc'},{'id': '78', 'type': 'None', 'children': []},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'augmented_assignment', 'children': ['82', '83'], 'value': '+='},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '83', 'type': 'list', 'children': ['84'], 'value': "[asc is True and b'ASC' or b'DESC']"},{'id': '84', 'type': 'boolean_operator', 'children': ['85', '90'], 'value': 'or'},{'id': '85', 'type': 'boolean_operator', 'children': ['86', '89'], 'value': 'and'},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': 'is'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'asc'},{'id': '88', 'type': 'True', 'children': []},{'id': '89', 'type': 'string', 'children': [], 'value': "b'ASC'"},{'id': '90', 'type': 'string', 'children': [], 'value': "b'DESC'"},{'id': '91', 'type': 'if_statement', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'augmented_assignment', 'children': ['96', '97'], 'value': '+='},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '97', 'type': 'list', 'children': ['98'], 'value': "[b'ALPHA']"},{'id': '98', 'type': 'string', 'children': [], 'value': "b'ALPHA'"},{'id': '99', 'type': 'if_statement', 'children': ['100', '103']},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': 'is'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '102', 'type': 'None', 'children': []},{'id': '103', 'type': 'block', 'children': ['104']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'augmented_assignment', 'children': ['106', '107'], 'value': '+='},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '107', 'type': 'list', 'children': ['108', '109'], 'value': "[b'STORE', store]"},{'id': '108', 'type': 'string', 'children': [], 'value': "b'STORE'"},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '110', 'type': 'return_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '115', 'type': 'argument_list', 'children': ['116', '117', '118']},{'id': '116', 'type': 'string', 'children': [], 'value': "b'SORT'"},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '118', 'type': 'list_splat', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'args'} | def sort(self, key, *get_patterns,
by=None, offset=None, count=None,
asc=None, alpha=False, store=None):
args = []
if by is not None:
args += [b'BY', by]
if offset is not None and count is not None:
args += [b'LIMIT', offset, count]
if get_patterns:
args += sum(([b'GET', pattern] for pattern in get_patterns), [])
if asc is not None:
args += [asc is True and b'ASC' or b'DESC']
if alpha:
args += [b'ALPHA']
if store is not None:
args += [b'STORE', store]
return self.execute(b'SORT', key, *args) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'zadd'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '8', 'type': 'list_splat_pattern', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'pairs'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'exist'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'block', 'children': ['14', '29', '44', '63', '84', '88', '116', '125', '135']},{'id': '14', 'type': 'if_statement', 'children': ['15', '23']},{'id': '15', 'type': 'not_operator', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '18', 'type': 'argument_list', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '20', 'type': 'tuple', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'raise_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'string', 'children': [], 'value': '"score argument must be int or float"'},{'id': '29', 'type': 'if_statement', 'children': ['30', '38']},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '37'], 'value': '!='},{'id': '31', 'type': 'binary_operator', 'children': ['32', '36'], 'value': '%'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'pairs'},{'id': '36', 'type': 'integer', 'children': [], 'value': '2'},{'id': '37', 'type': 'integer', 'children': [], 'value': '0'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'raise_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'string', 'children': [], 'value': '"length of pairs must be even number"'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '47', 'type': 'generator_expression', 'children': ['48', '49', '57']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '49', 'type': 'for_in_clause', 'children': ['50', '53']},{'id': '50', 'type': 'pattern_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'pairs'},{'id': '57', 'type': 'if_clause', 'children': ['58']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '62'], 'value': '=='},{'id': '59', 'type': 'binary_operator', 'children': ['60', '61'], 'value': '%'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '61', 'type': 'integer', 'children': [], 'value': '2'},{'id': '62', 'type': 'integer', 'children': [], 'value': '0'},{'id': '63', 'type': 'if_statement', 'children': ['64', '78']},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '66', 'type': 'generator_expression', 'children': ['67', '75']},{'id': '67', 'type': 'not_operator', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '70', 'type': 'argument_list', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '72', 'type': 'tuple', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '75', 'type': 'for_in_clause', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'raise_statement', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'string', 'children': [], 'value': '"all scores must be int or float"'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '87', 'type': 'list', 'children': [], 'value': '[]'},{'id': '88', 'type': 'if_statement', 'children': ['89', '94', '102']},{'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': 'is'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'exist'},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'ZSET_IF_EXIST'},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'string', 'children': [], 'value': "b'XX'"},{'id': '102', 'type': 'elif_clause', 'children': ['103', '108']},{'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': 'is'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'exist'},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'ZSET_IF_NOT_EXIST'},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'string', 'children': [], 'value': "b'NX'"},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'list', 'children': ['123', '124'], 'value': '[score, member]'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '125', 'type': 'if_statement', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'pairs'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'pairs'},{'id': '135', 'type': 'return_statement', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '140', 'type': 'argument_list', 'children': ['141', '142', '143']},{'id': '141', 'type': 'string', 'children': [], 'value': "b'ZADD'"},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '143', 'type': 'list_splat', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'args'} | def zadd(self, key, score, member, *pairs, exist=None):
if not isinstance(score, (int, float)):
raise TypeError("score argument must be int or float")
if len(pairs) % 2 != 0:
raise TypeError("length of pairs must be even number")
scores = (item for i, item in enumerate(pairs) if i % 2 == 0)
if any(not isinstance(s, (int, float)) for s in scores):
raise TypeError("all scores must be int or float")
args = []
if exist is self.ZSET_IF_EXIST:
args.append(b'XX')
elif exist is self.ZSET_IF_NOT_EXIST:
args.append(b'NX')
args.extend([score, member])
if pairs:
args.extend(pairs)
return self.execute(b'ZADD', key, *args) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '22']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'zcount'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '12', '18', '19']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '10', 'type': 'argument_list', 'children': ['11']},{'id': '11', 'type': 'string', 'children': [], 'value': "'-inf'"},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'string', 'children': [], 'value': "'inf'"},{'id': '18', 'type': 'keyword_separator', 'children': []},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'block', 'children': ['23', '38', '53', '63']},{'id': '23', 'type': 'if_statement', 'children': ['24', '32']},{'id': '24', 'type': 'not_operator', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '29', 'type': 'tuple', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'raise_statement', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'string', 'children': [], 'value': '"min argument must be int or float"'},{'id': '38', 'type': 'if_statement', 'children': ['39', '47']},{'id': '39', 'type': 'not_operator', 'children': ['40']},{'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': 'max'},{'id': '44', 'type': 'tuple', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'raise_statement', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'string', 'children': [], 'value': '"max argument must be int or float"'},{'id': '53', 'type': 'if_statement', 'children': ['54', '57']},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': '>'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'raise_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'string', 'children': [], 'value': '"min could not be greater than max"'},{'id': '63', 'type': 'return_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': 'execute'},{'id': '68', 'type': 'argument_list', 'children': ['69', '70', '71']},{'id': '69', 'type': 'string', 'children': [], 'value': "b'ZCOUNT'"},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '71', 'type': 'list_splat', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': '_encode_min_max'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76', '77']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'max'} | def zcount(self, key, min=float('-inf'), max=float('inf'),
*, exclude=None):
if not isinstance(min, (int, float)):
raise TypeError("min argument must be int or float")
if not isinstance(max, (int, float)):
raise TypeError("max argument must be int or float")
if min > max:
raise ValueError("min could not be greater than max")
return self.execute(b'ZCOUNT', key,
*_encode_min_max(exclude, min, max)) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'zincrby'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'increment'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '8', 'type': 'block', 'children': ['9', '24', '36']},{'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': 'increment'},{'id': '15', 'type': 'tuple', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'float'},{'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': '"increment argument must be int or float"'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'fut'},{'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': 'execute'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33', '34', '35']},{'id': '32', 'type': 'string', 'children': [], 'value': "b'ZINCRBY'"},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'increment'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '36', 'type': 'return_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'wait_convert'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'fut'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'int_or_float'} | def zincrby(self, key, increment, member):
if not isinstance(increment, (int, float)):
raise TypeError("increment argument must be int or float")
fut = self.execute(b'ZINCRBY', key, increment, member)
return wait_convert(fut, int_or_float) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'zrem'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '7', 'type': 'list_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'members'},{'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': 'execute'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17', '18', '19']},{'id': '16', 'type': 'string', 'children': [], 'value': "b'ZREM'"},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '19', 'type': 'list_splat', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'members'} | def zrem(self, key, member, *members):
return self.execute(b'ZREM', key, member, *members) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'zremrangebylex'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '8', 'type': 'string', 'children': [], 'value': "b'-'"},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '11', 'type': 'string', 'children': [], 'value': "b'+'"},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'include_min'},{'id': '14', 'type': 'True', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'include_max'},{'id': '17', 'type': 'True', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '32', '45', '61', '77']},{'id': '19', 'type': 'if_statement', 'children': ['20', '26']},{'id': '20', 'type': 'not_operator', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'raise_statement', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'string', 'children': [], 'value': '"min argument must be bytes"'},{'id': '32', 'type': 'if_statement', 'children': ['33', '39']},{'id': '33', 'type': 'not_operator', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'raise_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'string', 'children': [], 'value': '"max argument must be bytes"'},{'id': '45', 'type': 'if_statement', 'children': ['46', '50']},{'id': '46', 'type': 'not_operator', 'children': ['47']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': '=='},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '49', 'type': 'string', 'children': [], 'value': "b'-'"},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '54', 'type': 'binary_operator', 'children': ['55', '60'], 'value': '+'},{'id': '55', 'type': '()', 'children': ['56']},{'id': '56', 'type': 'conditional_expression', 'children': ['57', '58', '59'], 'value': 'if'},{'id': '57', 'type': 'string', 'children': [], 'value': "b'['"},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'include_min'},{'id': '59', 'type': 'string', 'children': [], 'value': "b'('"},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '61', 'type': 'if_statement', 'children': ['62', '66']},{'id': '62', 'type': 'not_operator', 'children': ['63']},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': '=='},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '65', 'type': 'string', 'children': [], 'value': "b'+'"},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '70', 'type': 'binary_operator', 'children': ['71', '76'], 'value': '+'},{'id': '71', 'type': '()', 'children': ['72']},{'id': '72', 'type': 'conditional_expression', 'children': ['73', '74', '75'], 'value': 'if'},{'id': '73', 'type': 'string', 'children': [], 'value': "b'['"},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'include_max'},{'id': '75', 'type': 'string', 'children': [], 'value': "b'('"},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '77', 'type': 'return_statement', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '82', 'type': 'argument_list', 'children': ['83', '84', '85', '86']},{'id': '83', 'type': 'string', 'children': [], 'value': "b'ZREMRANGEBYLEX'"},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'max'} | def zremrangebylex(self, key, min=b'-', max=b'+',
include_min=True, include_max=True):
if not isinstance(min, bytes):
raise TypeError("min argument must be bytes")
if not isinstance(max, bytes):
raise TypeError("max argument must be bytes")
if not min == b'-':
min = (b'[' if include_min else b'(') + min
if not max == b'+':
max = (b'[' if include_max else b'(') + max
return self.execute(b'ZREMRANGEBYLEX', key, min, max) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'zremrangebyrank'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '8', 'type': 'block', 'children': ['9', '22', '35']},{'id': '9', 'type': 'if_statement', 'children': ['10', '16']},{'id': '10', 'type': 'not_operator', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '13', 'type': 'argument_list', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'raise_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'string', 'children': [], 'value': '"start argument must be int"'},{'id': '22', 'type': 'if_statement', 'children': ['23', '29']},{'id': '23', 'type': 'not_operator', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'raise_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'string', 'children': [], 'value': '"stop argument must be int"'},{'id': '35', 'type': 'return_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42', '43', '44']},{'id': '41', 'type': 'string', 'children': [], 'value': "b'ZREMRANGEBYRANK'"},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'stop'} | def zremrangebyrank(self, key, start, stop):
if not isinstance(start, int):
raise TypeError("start argument must be int")
if not isinstance(stop, int):
raise TypeError("stop argument must be int")
return self.execute(b'ZREMRANGEBYRANK', key, start, stop) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '22']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'zremrangebyscore'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '12', '18', '19']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '10', 'type': 'argument_list', 'children': ['11']},{'id': '11', 'type': 'string', 'children': [], 'value': "'-inf'"},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'string', 'children': [], 'value': "'inf'"},{'id': '18', 'type': 'keyword_separator', 'children': []},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'block', 'children': ['23', '38', '53', '64']},{'id': '23', 'type': 'if_statement', 'children': ['24', '32']},{'id': '24', 'type': 'not_operator', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '29', 'type': 'tuple', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'raise_statement', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'string', 'children': [], 'value': '"min argument must be int or float"'},{'id': '38', 'type': 'if_statement', 'children': ['39', '47']},{'id': '39', 'type': 'not_operator', 'children': ['40']},{'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': 'max'},{'id': '44', 'type': 'tuple', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'raise_statement', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'string', 'children': [], 'value': '"max argument must be int or float"'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '58']},{'id': '55', 'type': 'pattern_list', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': '_encode_min_max'},{'id': '60', 'type': 'argument_list', 'children': ['61', '62', '63']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '64', 'type': 'return_statement', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71', '72', '73']},{'id': '70', 'type': 'string', 'children': [], 'value': "b'ZREMRANGEBYSCORE'"},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'max'} | def zremrangebyscore(self, key, min=float('-inf'), max=float('inf'),
*, exclude=None):
if not isinstance(min, (int, float)):
raise TypeError("min argument must be int or float")
if not isinstance(max, (int, float)):
raise TypeError("max argument must be int or float")
min, max = _encode_min_max(exclude, min, max)
return self.execute(b'ZREMRANGEBYSCORE', key, min, max) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'zrevrange'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'withscores'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '13', 'type': 'identifier', 'children': [], 'value': '_NOTSET'},{'id': '14', 'type': 'block', 'children': ['15', '28', '41', '55', '72', '81']},{'id': '15', 'type': 'if_statement', 'children': ['16', '22']},{'id': '16', 'type': 'not_operator', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'raise_statement', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'string', 'children': [], 'value': '"start argument must be int"'},{'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': 'stop'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'raise_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'string', 'children': [], 'value': '"stop argument must be int"'},{'id': '41', 'type': 'if_statement', 'children': ['42', '43', '49']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'withscores'},{'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': 'args'},{'id': '47', 'type': 'list', 'children': ['48'], 'value': "[b'WITHSCORES']"},{'id': '48', 'type': 'string', 'children': [], 'value': "b'WITHSCORES'"},{'id': '49', 'type': 'else_clause', 'children': ['50']},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '54', 'type': 'list', 'children': [], 'value': '[]'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'fut'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64', '65', '66', '67', '69']},{'id': '63', 'type': 'string', 'children': [], 'value': "b'ZREVRANGE'"},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '67', 'type': 'list_splat', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '72', 'type': 'if_statement', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'withscores'},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'return_statement', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'wait_convert'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'fut'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'pairs_int_or_float'},{'id': '81', 'type': 'return_statement', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'fut'} | def zrevrange(self, key, start, stop, withscores=False, encoding=_NOTSET):
if not isinstance(start, int):
raise TypeError("start argument must be int")
if not isinstance(stop, int):
raise TypeError("stop argument must be int")
if withscores:
args = [b'WITHSCORES']
else:
args = []
fut = self.execute(b'ZREVRANGE', key, start, stop, *args,
encoding=encoding)
if withscores:
return wait_convert(fut, pairs_int_or_float)
return fut |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '34']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'zrevrangebyscore'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '12', '18', '19', '22', '25', '28', '31']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '10', 'type': 'argument_list', 'children': ['11']},{'id': '11', 'type': 'string', 'children': [], 'value': "'inf'"},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'string', 'children': [], 'value': "'-inf'"},{'id': '18', 'type': 'keyword_separator', 'children': []},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'withscores'},{'id': '24', 'type': 'False', 'children': []},{'id': '25', 'type': 'default_parameter', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'default_parameter', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'default_parameter', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '33', 'type': 'identifier', 'children': [], 'value': '_NOTSET'},{'id': '34', 'type': 'block', 'children': ['35', '50', '65', '90', '107', '124', '135', '139', '147', '166', '183', '192']},{'id': '35', 'type': 'if_statement', 'children': ['36', '44']},{'id': '36', 'type': 'not_operator', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '41', 'type': 'tuple', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'raise_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'string', 'children': [], 'value': '"min argument must be int or float"'},{'id': '50', 'type': 'if_statement', 'children': ['51', '59']},{'id': '51', 'type': 'not_operator', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '56', 'type': 'tuple', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'float'},{'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': 'TypeError'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'string', 'children': [], 'value': '"max argument must be int or float"'},{'id': '65', 'type': 'if_statement', 'children': ['66', '84']},{'id': '66', 'type': 'boolean_operator', 'children': ['67', '75', '76'], 'value': 'or'},{'id': '67', 'type': '()', 'children': ['68']},{'id': '68', 'type': 'boolean_operator', 'children': ['69', '72'], 'value': 'and'},{'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': 'is'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '71', 'type': 'None', 'children': []},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': 'is'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '74', 'type': 'None', 'children': []},{'id': '75', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '76', 'type': '()', 'children': ['77']},{'id': '77', 'type': 'boolean_operator', 'children': ['78', '81'], 'value': 'and'},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': 'is'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '80', 'type': 'None', 'children': []},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': 'is'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '83', 'type': 'None', 'children': []},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'raise_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'string', 'children': [], 'value': '"offset and count must both be specified"'},{'id': '90', 'type': 'if_statement', 'children': ['91', '101']},{'id': '91', 'type': 'boolean_operator', 'children': ['92', '95'], 'value': 'and'},{'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': 'is'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '94', 'type': 'None', 'children': []},{'id': '95', 'type': 'not_operator', 'children': ['96']},{'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': 'offset'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'int'},{'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': 'TypeError'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'string', 'children': [], 'value': '"offset argument must be int"'},{'id': '107', 'type': 'if_statement', 'children': ['108', '118']},{'id': '108', 'type': 'boolean_operator', 'children': ['109', '112'], 'value': 'and'},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': 'is'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '111', 'type': 'None', 'children': []},{'id': '112', 'type': 'not_operator', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '115', 'type': 'argument_list', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'raise_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'string', 'children': [], 'value': '"count argument must be int"'},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '129']},{'id': '126', 'type': 'pattern_list', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': '_encode_min_max'},{'id': '131', 'type': 'argument_list', 'children': ['132', '133', '134']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '138', 'type': 'list', 'children': [], 'value': '[]'},{'id': '139', 'type': 'if_statement', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'withscores'},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '145', 'type': 'list', 'children': ['146'], 'value': "[b'WITHSCORES']"},{'id': '146', 'type': 'string', 'children': [], 'value': "b'WITHSCORES'"},{'id': '147', 'type': 'if_statement', 'children': ['148', '155']},{'id': '148', 'type': 'boolean_operator', 'children': ['149', '152'], 'value': 'and'},{'id': '149', 'type': 'comparison_operator', 'children': ['150', '151'], 'value': 'is'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '151', 'type': 'None', 'children': []},{'id': '152', 'type': 'comparison_operator', 'children': ['153', '154'], 'value': 'is'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '154', 'type': 'None', 'children': []},{'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': 'args'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'list', 'children': ['163', '164', '165'], 'value': "[b'LIMIT', offset, count]"},{'id': '163', 'type': 'string', 'children': [], 'value': "b'LIMIT'"},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'fut'},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '173', 'type': 'argument_list', 'children': ['174', '175', '176', '177', '178', '180']},{'id': '174', 'type': 'string', 'children': [], 'value': "b'ZREVRANGEBYSCORE'"},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '178', 'type': 'list_splat', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '180', 'type': 'keyword_argument', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '183', 'type': 'if_statement', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'withscores'},{'id': '185', 'type': 'block', 'children': ['186']},{'id': '186', 'type': 'return_statement', 'children': ['187']},{'id': '187', 'type': 'call', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'wait_convert'},{'id': '189', 'type': 'argument_list', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'fut'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'pairs_int_or_float'},{'id': '192', 'type': 'return_statement', 'children': ['193']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'fut'} | def zrevrangebyscore(self, key, max=float('inf'), min=float('-inf'),
*, exclude=None, withscores=False,
offset=None, count=None, encoding=_NOTSET):
if not isinstance(min, (int, float)):
raise TypeError("min argument must be int or float")
if not isinstance(max, (int, float)):
raise TypeError("max argument must be int or float")
if (offset is not None and count is None) or \
(count is not None and offset is None):
raise TypeError("offset and count must both be specified")
if offset is not None and not isinstance(offset, int):
raise TypeError("offset argument must be int")
if count is not None and not isinstance(count, int):
raise TypeError("count argument must be int")
min, max = _encode_min_max(exclude, min, max)
args = []
if withscores:
args = [b'WITHSCORES']
if offset is not None and count is not None:
args.extend([b'LIMIT', offset, count])
fut = self.execute(b'ZREVRANGEBYSCORE', key, max, min, *args,
encoding=encoding)
if withscores:
return wait_convert(fut, pairs_int_or_float)
return fut |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'zscore'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '7', 'type': 'block', 'children': ['8', '19']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'fut'},{'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': 'execute'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17', '18']},{'id': '16', 'type': 'string', 'children': [], 'value': "b'ZSCORE'"},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '19', 'type': 'return_statement', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'wait_convert'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'fut'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'optional_int_or_float'} | def zscore(self, key, member):
fut = self.execute(b'ZSCORE', key, member)
return wait_convert(fut, optional_int_or_float) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'zunionstore'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'destkey'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '7', 'type': 'list_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'with_weights'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'aggregate'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '23', '30', '34', '94', '142', '155']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '19', 'type': 'binary_operator', 'children': ['20', '22'], 'value': '+'},{'id': '20', 'type': 'tuple', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'numkeys'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '33', 'type': 'list', 'children': [], 'value': '[]'},{'id': '34', 'type': 'if_statement', 'children': ['35', '36', '85']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'with_weights'},{'id': '36', 'type': 'block', 'children': ['37', '53', '58', '78']},{'id': '37', 'type': 'assert_statement', 'children': ['38', '51']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '40', 'type': 'generator_expression', 'children': ['41', '48']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '45', 'type': 'tuple', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '48', 'type': 'for_in_clause', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '51', 'type': '()', 'children': ['52']},{'id': '52', 'type': 'string', 'children': [], 'value': '"All key arguments must be (key, weight) tuples"'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '56', 'type': 'list', 'children': ['57'], 'value': "['WEIGHTS']"},{'id': '57', 'type': 'string', 'children': [], 'value': "'WEIGHTS'"},{'id': '58', 'type': 'for_statement', 'children': ['59', '62', '63']},{'id': '59', 'type': 'pattern_list', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'weight'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '63', 'type': 'block', 'children': ['64', '71']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'key'},{'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': 'weights'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'weight'},{'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': 'args'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '85', 'type': 'else_clause', 'children': ['86']},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '94', 'type': 'if_statement', 'children': ['95', '100', '110', '126']},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': 'is'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'aggregate'},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'ZSET_AGGREGATE_SUM'},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'tuple', 'children': ['108', '109']},{'id': '108', 'type': 'string', 'children': [], 'value': "'AGGREGATE'"},{'id': '109', 'type': 'string', 'children': [], 'value': "'SUM'"},{'id': '110', 'type': 'elif_clause', 'children': ['111', '116']},{'id': '111', 'type': 'comparison_operator', 'children': ['112', '113'], 'value': 'is'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'aggregate'},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'ZSET_AGGREGATE_MAX'},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'tuple', 'children': ['124', '125']},{'id': '124', 'type': 'string', 'children': [], 'value': "'AGGREGATE'"},{'id': '125', 'type': 'string', 'children': [], 'value': "'MAX'"},{'id': '126', 'type': 'elif_clause', 'children': ['127', '132']},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': 'is'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'aggregate'},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'ZSET_AGGREGATE_MIN'},{'id': '132', 'type': 'block', 'children': ['133']},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'tuple', 'children': ['140', '141']},{'id': '140', 'type': 'string', 'children': [], 'value': "'AGGREGATE'"},{'id': '141', 'type': 'string', 'children': [], 'value': "'MIN'"},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'fut'},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '149', 'type': 'argument_list', 'children': ['150', '151', '152', '153']},{'id': '150', 'type': 'string', 'children': [], 'value': "b'ZUNIONSTORE'"},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'destkey'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'numkeys'},{'id': '153', 'type': 'list_splat', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '155', 'type': 'return_statement', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'fut'} | def zunionstore(self, destkey, key, *keys,
with_weights=False, aggregate=None):
keys = (key,) + keys
numkeys = len(keys)
args = []
if with_weights:
assert all(isinstance(val, (list, tuple)) for val in keys), (
"All key arguments must be (key, weight) tuples")
weights = ['WEIGHTS']
for key, weight in keys:
args.append(key)
weights.append(weight)
args.extend(weights)
else:
args.extend(keys)
if aggregate is self.ZSET_AGGREGATE_SUM:
args.extend(('AGGREGATE', 'SUM'))
elif aggregate is self.ZSET_AGGREGATE_MAX:
args.extend(('AGGREGATE', 'MAX'))
elif aggregate is self.ZSET_AGGREGATE_MIN:
args.extend(('AGGREGATE', 'MIN'))
fut = self.execute(b'ZUNIONSTORE', destkey, numkeys, *args)
return fut |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'zscan'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '8', 'type': 'integer', 'children': [], 'value': '0'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '20', '31', '42', '55', '74']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '19', 'type': 'list', 'children': [], 'value': '[]'},{'id': '20', 'type': 'if_statement', 'children': ['21', '24']},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'is'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'augmented_assignment', 'children': ['27', '28'], 'value': '+='},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '28', 'type': 'list', 'children': ['29', '30'], 'value': "[b'MATCH', match]"},{'id': '29', 'type': 'string', 'children': [], 'value': "b'MATCH'"},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '31', 'type': 'if_statement', 'children': ['32', '35']},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'is'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'augmented_assignment', 'children': ['38', '39'], 'value': '+='},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '39', 'type': 'list', 'children': ['40', '41'], 'value': "[b'COUNT', count]"},{'id': '40', 'type': 'string', 'children': [], 'value': "b'COUNT'"},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'fut'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51', '52', '53']},{'id': '50', 'type': 'string', 'children': [], 'value': "b'ZSCAN'"},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '53', 'type': 'list_splat', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '55', 'type': 'function_definition', 'children': ['56', '57', '59']},{'id': '56', 'type': 'function_name', 'children': [], 'value': '_converter'},{'id': '57', 'type': 'parameters', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'return_statement', 'children': ['61']},{'id': '61', 'type': 'tuple', 'children': ['62', '68']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '67', 'type': 'integer', 'children': [], 'value': '0'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'pairs_int_or_float'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'subscript', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '73', 'type': 'integer', 'children': [], 'value': '1'},{'id': '74', 'type': 'return_statement', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'wait_convert'},{'id': '77', 'type': 'argument_list', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'fut'},{'id': '79', 'type': 'identifier', 'children': [], 'value': '_converter'} | def zscan(self, key, cursor=0, match=None, count=None):
args = []
if match is not None:
args += [b'MATCH', match]
if count is not None:
args += [b'COUNT', count]
fut = self.execute(b'ZSCAN', key, cursor, *args)
def _converter(obj):
return (int(obj[0]), pairs_int_or_float(obj[1]))
return wait_convert(fut, _converter) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'zpopmin'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'keyword_separator', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_NOTSET'},{'id': '13', 'type': 'block', 'children': ['14', '31', '35', '48', '63']},{'id': '14', 'type': 'if_statement', 'children': ['15', '25']},{'id': '15', 'type': 'boolean_operator', 'children': ['16', '19'], 'value': 'and'},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'not_operator', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'raise_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'string', 'children': [], 'value': '"count argument must be int"'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '34', 'type': 'list', 'children': [], 'value': '[]'},{'id': '35', 'type': 'if_statement', 'children': ['36', '39']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'is'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '38', 'type': 'None', 'children': []},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'list', 'children': ['47'], 'value': '[count]'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'fut'},{'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': 'execute'},{'id': '55', 'type': 'argument_list', 'children': ['56', '57', '58', '60']},{'id': '56', 'type': 'string', 'children': [], 'value': "b'ZPOPMIN'"},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '58', 'type': 'list_splat', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '63', 'type': 'return_statement', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'fut'} | def zpopmin(self, key, count=None, *, encoding=_NOTSET):
if count is not None and not isinstance(count, int):
raise TypeError("count argument must be int")
args = []
if count is not None:
args.extend([count])
fut = self.execute(b'ZPOPMIN', key, *args, encoding=encoding)
return fut |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'zpopmax'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'keyword_separator', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_NOTSET'},{'id': '13', 'type': 'block', 'children': ['14', '31', '35', '48', '63']},{'id': '14', 'type': 'if_statement', 'children': ['15', '25']},{'id': '15', 'type': 'boolean_operator', 'children': ['16', '19'], 'value': 'and'},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'not_operator', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'raise_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'string', 'children': [], 'value': '"count argument must be int"'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '34', 'type': 'list', 'children': [], 'value': '[]'},{'id': '35', 'type': 'if_statement', 'children': ['36', '39']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'is'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '38', 'type': 'None', 'children': []},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'list', 'children': ['47'], 'value': '[count]'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'fut'},{'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': 'execute'},{'id': '55', 'type': 'argument_list', 'children': ['56', '57', '58', '60']},{'id': '56', 'type': 'string', 'children': [], 'value': "b'ZPOPMAX'"},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '58', 'type': 'list_splat', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '63', 'type': 'return_statement', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'fut'} | def zpopmax(self, key, count=None, *, encoding=_NOTSET):
if count is not None and not isinstance(count, int):
raise TypeError("count argument must be int")
args = []
if count is not None:
args.extend([count])
fut = self.execute(b'ZPOPMAX', key, *args, encoding=encoding)
return fut |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'uniq'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '5', 'type': 'block', 'children': ['6', '107']},{'id': '6', 'type': 'try_statement', 'children': ['7', '27']},{'id': '7', 'type': 'block', 'children': ['8']},{'id': '8', 'type': 'return_statement', 'children': ['9']},{'id': '9', 'type': 'comparison_operator', 'children': ['10', '23'], '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': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '15', 'type': 'generator_expression', 'children': ['16', '20']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'unbool'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '20', 'type': 'for_in_clause', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'container'},{'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': 'container'},{'id': '27', 'type': 'except_clause', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'try_statement', 'children': ['31', '73']},{'id': '31', 'type': 'block', 'children': ['32', '45', '56']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '37', 'type': 'generator_expression', 'children': ['38', '42']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'unbool'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '42', 'type': 'for_in_clause', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'sliced'},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'islice'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54', '55']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '54', 'type': 'integer', 'children': [], 'value': '1'},{'id': '55', 'type': 'None', 'children': []},{'id': '56', 'type': 'for_statement', 'children': ['57', '60', '65']},{'id': '57', 'type': 'pattern_list', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'sliced'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'if_statement', 'children': ['67', '70']},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': '=='},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'return_statement', 'children': ['72']},{'id': '72', 'type': 'False', 'children': []},{'id': '73', 'type': 'except_clause', 'children': ['74', '77']},{'id': '74', 'type': 'tuple', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '77', 'type': 'block', 'children': ['78', '82']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'seen'},{'id': '81', 'type': 'list', 'children': [], 'value': '[]'},{'id': '82', 'type': 'for_statement', 'children': ['83', '84', '85']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '85', 'type': 'block', 'children': ['86', '93', '100']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'unbool'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '93', 'type': 'if_statement', 'children': ['94', '97']},{'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': 'in'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'seen'},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'return_statement', 'children': ['99']},{'id': '99', 'type': 'False', 'children': []},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'seen'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '107', 'type': 'return_statement', 'children': ['108']},{'id': '108', 'type': 'True', 'children': []} | def uniq(container):
try:
return len(set(unbool(i) for i in container)) == len(container)
except TypeError:
try:
sort = sorted(unbool(i) for i in container)
sliced = itertools.islice(sort, 1, None)
for i, j in zip(sort, sliced):
if i == j:
return False
except (NotImplementedError, TypeError):
seen = []
for e in container:
e = unbool(e)
if e in seen:
return False
seen.append(e)
return True |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'split_traversal'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'traversal'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'edges_hash'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '24', '46', '66', '83', '93', '149', '255', '264']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'traversal'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'asanyarray'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'traversal'},{'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'int64'},{'id': '24', 'type': 'if_statement', 'children': ['25', '28']},{'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'is'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'edges_hash'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'edges_hash'},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'grouping'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'hashable_rows'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'axis'},{'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': 'trav_edge'},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'column_stack'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'tuple', 'children': ['55', '61']},{'id': '55', 'type': 'subscript', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'traversal'},{'id': '57', 'type': 'slice', 'children': ['58', '59']},{'id': '58', 'type': 'colon', 'children': []},{'id': '59', 'type': 'unary_operator', 'children': ['60'], 'value': '-'},{'id': '60', 'type': 'integer', 'children': [], 'value': '1'},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'traversal'},{'id': '63', 'type': 'slice', 'children': ['64', '65']},{'id': '64', 'type': 'integer', 'children': [], 'value': '1'},{'id': '65', 'type': 'colon', 'children': []},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'trav_hash'},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'grouping'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'hashable_rows'},{'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': 'np'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'trav_edge'},{'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '82', 'type': 'integer', 'children': [], 'value': '1'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'contained'},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'in1d'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'trav_hash'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'edges_hash'},{'id': '93', 'type': 'if_statement', 'children': ['94', '99', '105']},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'contained'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '98', 'type': 'argument_list', 'children': []},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '103', 'type': 'list', 'children': ['104'], 'value': '[traversal]'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'traversal'},{'id': '105', 'type': 'else_clause', 'children': ['106']},{'id': '106', 'type': 'block', 'children': ['107', '122']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'blocks'},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'grouping'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'blocks'},{'id': '114', 'type': 'argument_list', 'children': ['115', '116', '119']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'contained'},{'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'min_len'},{'id': '118', 'type': 'integer', 'children': [], 'value': '1'},{'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'only_nonzero'},{'id': '121', 'type': 'True', 'children': []},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '125', 'type': 'list_comprehension', 'children': ['126', '146']},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '130', 'type': 'argument_list', 'children': ['131', '138']},{'id': '131', 'type': 'subscript', 'children': ['132', '135', '137']},{'id': '132', 'type': 'subscript', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'trav_edge'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '135', 'type': 'slice', 'children': ['136']},{'id': '136', 'type': 'colon', 'children': []},{'id': '137', 'type': 'integer', 'children': [], 'value': '0'},{'id': '138', 'type': 'subscript', 'children': ['139', '145']},{'id': '139', 'type': 'subscript', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'trav_edge'},{'id': '141', 'type': 'subscript', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '143', 'type': 'unary_operator', 'children': ['144'], 'value': '-'},{'id': '144', 'type': 'integer', 'children': [], 'value': '1'},{'id': '145', 'type': 'integer', 'children': [], 'value': '1'},{'id': '146', 'type': 'for_in_clause', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'blocks'},{'id': '149', 'type': 'for_statement', 'children': ['150', '153', '157']},{'id': '150', 'type': 'pattern_list', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '157', 'type': 'block', 'children': ['158', '176', '185', '201', '211', '229']},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '163']},{'id': '160', 'type': 'subscript', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'asanyarray'},{'id': '167', 'type': 'argument_list', 'children': ['168', '171']},{'id': '168', 'type': 'subscript', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '171', 'type': 'keyword_argument', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'int64'},{'id': '176', 'type': 'if_statement', 'children': ['177', '183']},{'id': '177', 'type': 'comparison_operator', 'children': ['178', '182'], 'value': '<='},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '182', 'type': 'integer', 'children': [], 'value': '2'},{'id': '183', 'type': 'block', 'children': ['184']},{'id': '184', 'type': 'continue_statement', 'children': []},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'list', 'children': ['194', '197'], 'value': '[t[0], t[-1]]'},{'id': '194', 'type': 'subscript', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '196', 'type': 'integer', 'children': [], 'value': '0'},{'id': '197', 'type': 'subscript', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '199', 'type': 'unary_operator', 'children': ['200'], 'value': '-'},{'id': '200', 'type': 'integer', 'children': [], 'value': '1'},{'id': '201', 'type': 'if_statement', 'children': ['202', '209']},{'id': '202', 'type': 'comparison_operator', 'children': ['203', '208'], 'value': '=='},{'id': '203', 'type': 'call', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'ptp'},{'id': '207', 'type': 'argument_list', 'children': []},{'id': '208', 'type': 'integer', 'children': [], 'value': '0'},{'id': '209', 'type': 'block', 'children': ['210']},{'id': '210', 'type': 'continue_statement', 'children': []},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '214', 'type': 'subscript', 'children': ['215', '228']},{'id': '215', 'type': 'call', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'grouping'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'hashable_rows'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'reshape'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'tuple', 'children': ['226', '227']},{'id': '226', 'type': 'integer', 'children': [], 'value': '1'},{'id': '227', 'type': 'integer', 'children': [], 'value': '2'},{'id': '228', 'type': 'integer', 'children': [], 'value': '0'},{'id': '229', 'type': 'if_statement', 'children': ['230', '233']},{'id': '230', 'type': 'comparison_operator', 'children': ['231', '232'], 'value': 'in'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'edges_hash'},{'id': '233', 'type': 'block', 'children': ['234']},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'assignment', 'children': ['236', '239']},{'id': '236', 'type': 'subscript', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '239', 'type': 'call', 'children': ['240', '251']},{'id': '240', 'type': 'attribute', 'children': ['241', '250']},{'id': '241', 'type': 'call', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '245', 'type': 'argument_list', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '247', 'type': 'subscript', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '249', 'type': 'integer', 'children': [], 'value': '0'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '251', 'type': 'argument_list', 'children': ['252']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'int64'},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'assignment', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '258', 'type': 'call', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '262', 'type': 'argument_list', 'children': ['263']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '264', 'type': 'return_statement', 'children': ['265']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'result'} | def split_traversal(traversal,
edges,
edges_hash=None):
traversal = np.asanyarray(traversal,
dtype=np.int64)
if edges_hash is None:
edges_hash = grouping.hashable_rows(
np.sort(edges, axis=1))
trav_edge = np.column_stack((traversal[:-1],
traversal[1:]))
trav_hash = grouping.hashable_rows(
np.sort(trav_edge, axis=1))
contained = np.in1d(trav_hash, edges_hash)
if contained.all():
split = [traversal]
else:
blocks = grouping.blocks(contained,
min_len=1,
only_nonzero=True)
split = [np.append(trav_edge[b][:, 0],
trav_edge[b[-1]][1])
for b in blocks]
for i, t in enumerate(split):
split[i] = np.asanyarray(split[i], dtype=np.int64)
if len(t) <= 2:
continue
edge = np.sort([t[0], t[-1]])
if edge.ptp() == 0:
continue
close = grouping.hashable_rows(edge.reshape((1, 2)))[0]
if close in edges_hash:
split[i] = np.append(t, t[0]).astype(np.int64)
result = np.array(split)
return result |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'fill_traversals'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'traversals'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'edges_hash'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '24', '33', '47', '61', '65', '87', '116', '161']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'asanyarray'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'int64'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '32', 'type': 'integer', 'children': [], 'value': '1'},{'id': '33', 'type': 'if_statement', 'children': ['34', '40']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '39'], 'value': '=='},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'traversals'},{'id': '39', 'type': 'integer', 'children': [], 'value': '0'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'return_statement', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'copy'},{'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': 'edges_hash'},{'id': '50', 'type': 'None', 'children': []},{'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': 'edges_hash'},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'grouping'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'hashable_rows'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'splits'},{'id': '64', 'type': 'list', 'children': [], 'value': '[]'},{'id': '65', 'type': 'for_statement', 'children': ['66', '67', '68']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'traversals'},{'id': '68', 'type': 'block', 'children': ['69']},{'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': 'splits'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'split_traversal'},{'id': '77', 'type': 'argument_list', 'children': ['78', '81', '84']},{'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'traversal'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'edges_hash'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'edges_hash'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'included'},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'util'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'vstack_empty'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'list_comprehension', 'children': ['96', '113']},{'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': 'column_stack'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'tuple', 'children': ['102', '108']},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '104', 'type': 'slice', 'children': ['105', '106']},{'id': '105', 'type': 'colon', 'children': []},{'id': '106', 'type': 'unary_operator', 'children': ['107'], 'value': '-'},{'id': '107', 'type': 'integer', 'children': [], 'value': '1'},{'id': '108', 'type': 'subscript', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '110', 'type': 'slice', 'children': ['111', '112']},{'id': '111', 'type': 'integer', 'children': [], 'value': '1'},{'id': '112', 'type': 'colon', 'children': []},{'id': '113', 'type': 'for_in_clause', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'splits'},{'id': '116', 'type': 'if_statement', 'children': ['117', '123', '151']},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '122'], 'value': '>'},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'included'},{'id': '122', 'type': 'integer', 'children': [], 'value': '0'},{'id': '123', 'type': 'block', 'children': ['124', '133']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'included'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '132', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'splits'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'grouping'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'boolean_rows'},{'id': '143', 'type': 'argument_list', 'children': ['144', '145', '146']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'included'},{'id': '146', 'type': 'keyword_argument', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'setdiff1d'},{'id': '151', 'type': 'else_clause', 'children': ['152']},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'splits'},{'id': '156', 'type': 'call', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '160', 'type': 'argument_list', 'children': []},{'id': '161', 'type': 'return_statement', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'splits'} | def fill_traversals(traversals, edges, edges_hash=None):
edges = np.asanyarray(edges, dtype=np.int64)
edges.sort(axis=1)
if len(traversals) == 0:
return edges.copy()
if edges_hash is None:
edges_hash = grouping.hashable_rows(edges)
splits = []
for nodes in traversals:
splits.extend(split_traversal(
traversal=nodes,
edges=edges,
edges_hash=edges_hash))
included = util.vstack_empty([np.column_stack((i[:-1], i[1:]))
for i in splits])
if len(included) > 0:
included.sort(axis=1)
splits.extend(grouping.boolean_rows(
edges,
included,
operation=np.setdiff1d))
else:
splits = edges.copy()
return splits |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'hashable_rows'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'digits'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '24', '34', '46', '154', '177', '197']},{'id': '9', 'type': 'if_statement', 'children': ['10', '16']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '15'], 'value': '=='},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '15', 'type': 'integer', 'children': [], 'value': '0'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'return_statement', 'children': ['18']},{'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': 'array'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'list', 'children': [], 'value': '[]'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'as_int'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'float_to_int'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'digits'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'digits'},{'id': '34', 'type': 'if_statement', 'children': ['35', '43']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '42'], 'value': '=='},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'as_int'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '42', 'type': 'integer', 'children': [], 'value': '1'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'return_statement', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'as_int'},{'id': '46', 'type': 'if_statement', 'children': ['47', '63']},{'id': '47', 'type': 'boolean_operator', 'children': ['48', '56'], 'value': 'and'},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '55'], 'value': '=='},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'as_int'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '55', 'type': 'integer', 'children': [], 'value': '2'},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '62'], 'value': '<='},{'id': '57', 'type': 'subscript', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'as_int'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '61', 'type': 'integer', 'children': [], 'value': '1'},{'id': '62', 'type': 'integer', 'children': [], 'value': '4'},{'id': '63', 'type': 'block', 'children': ['64', '82']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'precision'},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'int'},{'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': 'np'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'floor'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'binary_operator', 'children': ['76', '77'], 'value': '/'},{'id': '76', 'type': 'integer', 'children': [], 'value': '64'},{'id': '77', 'type': 'subscript', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'as_int'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '81', 'type': 'integer', 'children': [], 'value': '1'},{'id': '82', 'type': 'if_statement', 'children': ['83', '100']},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '94'], 'value': '<'},{'id': '84', 'type': 'call', 'children': ['85', '93']},{'id': '85', 'type': 'attribute', 'children': ['86', '92']},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'as_int'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '93', 'type': 'argument_list', 'children': []},{'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '**'},{'id': '95', 'type': 'integer', 'children': [], 'value': '2'},{'id': '96', 'type': '()', 'children': ['97']},{'id': '97', 'type': 'binary_operator', 'children': ['98', '99'], 'value': '-'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'precision'},{'id': '99', 'type': 'integer', 'children': [], 'value': '1'},{'id': '100', 'type': 'block', 'children': ['101', '118', '152']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'hashable'},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '108', 'type': 'argument_list', 'children': ['109', '113']},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'as_int'},{'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'int64'},{'id': '118', 'type': 'for_statement', 'children': ['119', '122', '135']},{'id': '119', 'type': 'pattern_list', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'attribute', 'children': ['126', '134']},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'as_int'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'int64'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '135', 'type': 'block', 'children': ['136']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'call', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'bitwise_xor'},{'id': '141', 'type': 'argument_list', 'children': ['142', '143', '149']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'hashable'},{'id': '143', 'type': 'binary_operator', 'children': ['144', '145'], 'value': '<<'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '145', 'type': '()', 'children': ['146']},{'id': '146', 'type': 'binary_operator', 'children': ['147', '148'], 'value': '*'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'precision'},{'id': '149', 'type': 'keyword_argument', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'hashable'},{'id': '152', 'type': 'return_statement', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'hashable'},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'tuple', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'void'},{'id': '166', 'type': 'binary_operator', 'children': ['167', '172'], 'value': '*'},{'id': '167', 'type': 'attribute', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'as_int'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'itemsize'},{'id': '172', 'type': 'subscript', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'as_int'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '176', 'type': 'integer', 'children': [], 'value': '1'},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'hashable'},{'id': '180', 'type': 'call', 'children': ['181', '194']},{'id': '181', 'type': 'attribute', 'children': ['182', '193']},{'id': '182', 'type': 'call', 'children': ['183', '191']},{'id': '183', 'type': 'attribute', 'children': ['184', '190']},{'id': '184', 'type': 'call', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'ascontiguousarray'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'as_int'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'view'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'reshape'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'unary_operator', 'children': ['196'], 'value': '-'},{'id': '196', 'type': 'integer', 'children': [], 'value': '1'},{'id': '197', 'type': 'return_statement', 'children': ['198']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'hashable'} | def hashable_rows(data, digits=None):
if len(data) == 0:
return np.array([])
as_int = float_to_int(data, digits=digits)
if len(as_int.shape) == 1:
return as_int
if len(as_int.shape) == 2 and as_int.shape[1] <= 4:
precision = int(np.floor(64 / as_int.shape[1]))
if np.abs(as_int).max() < 2**(precision - 1):
hashable = np.zeros(len(as_int), dtype=np.int64)
for offset, column in enumerate(as_int.astype(np.int64).T):
np.bitwise_xor(hashable,
column << (offset * precision),
out=hashable)
return hashable
dtype = np.dtype((np.void, as_int.dtype.itemsize * as_int.shape[1]))
hashable = np.ascontiguousarray(as_int).view(dtype).reshape(-1)
return hashable |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'interpolate_nans_1d'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '8', 'type': 'string', 'children': [], 'value': "'linear'"},{'id': '9', 'type': 'block', 'children': ['10', '19', '25', '31', '40', '117']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'x_sort_args'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '22', 'type': 'subscript', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'x_sort_args'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '28', 'type': 'subscript', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'x_sort_args'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'nans'},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'isnan'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '40', 'type': 'if_statement', 'children': ['41', '44', '66', '102']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': '=='},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '43', 'type': 'string', 'children': [], 'value': "'linear'"},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '50']},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'nans'},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'interp'},{'id': '54', 'type': 'argument_list', 'children': ['55', '58', '62']},{'id': '55', 'type': 'subscript', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'nans'},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '60', 'type': 'unary_operator', 'children': ['61'], 'value': '~'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'nans'},{'id': '62', 'type': 'subscript', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '64', 'type': 'unary_operator', 'children': ['65'], 'value': '~'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'nans'},{'id': '66', 'type': 'elif_clause', 'children': ['67', '70']},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': '=='},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '69', 'type': 'string', 'children': [], 'value': "'log'"},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '76']},{'id': '73', 'type': 'subscript', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'nans'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'interp'},{'id': '80', 'type': 'argument_list', 'children': ['81', '89', '98']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'nans'},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'subscript', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '96', 'type': 'unary_operator', 'children': ['97'], 'value': '~'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'nans'},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '100', 'type': 'unary_operator', 'children': ['101'], 'value': '~'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'nans'},{'id': '102', 'type': 'else_clause', 'children': ['103']},{'id': '103', 'type': 'block', 'children': ['104']},{'id': '104', 'type': 'raise_statement', 'children': ['105']},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'string', 'children': [], 'value': "'Unknown option for kind: {0}'"},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '117', 'type': 'return_statement', 'children': ['118']},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'x_sort_args'} | def interpolate_nans_1d(x, y, kind='linear'):
x_sort_args = np.argsort(x)
x = x[x_sort_args]
y = y[x_sort_args]
nans = np.isnan(y)
if kind == 'linear':
y[nans] = np.interp(x[nans], x[~nans], y[~nans])
elif kind == 'log':
y[nans] = np.interp(np.log(x[nans]), np.log(x[~nans]), y[~nans])
else:
raise ValueError('Unknown option for kind: {0}'.format(str(kind)))
return y[x_sort_args] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'interpolate_1d'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'xp'},{'id': '6', 'type': 'list_splat_pattern', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '8', 'type': 'dictionary_splat_pattern', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '10', 'type': 'block', 'children': ['11', '13', '25', '35', '50', '56', '68', '77', '87', '93', '103', '109', '118', '127', '136', '152', '161', '196', '235', '253', '263', '275', '294', '298', '397']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'fill_value'},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'string', 'children': [], 'value': "'fill_value'"},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'nan'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34']},{'id': '33', 'type': 'string', 'children': [], 'value': "'axis'"},{'id': '34', 'type': 'integer', 'children': [], 'value': '0'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '38', 'type': 'call', 'children': ['39', '47']},{'id': '39', 'type': 'attribute', 'children': ['40', '46']},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'asanyarray'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'reshape'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'unary_operator', 'children': ['49'], 'value': '-'},{'id': '49', 'type': 'integer', 'children': [], 'value': '1'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'xp'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'sort_args'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'xp'},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'sort_x'},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'sorter'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'broadcast_indices'},{'id': '82', 'type': 'argument_list', 'children': ['83', '84', '85', '86']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'xp'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'sort_args'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'xp'},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'xp'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'sorter'},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'variables'},{'id': '96', 'type': 'list_comprehension', 'children': ['97', '100']},{'id': '97', 'type': 'subscript', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'sorter'},{'id': '100', 'type': 'for_in_clause', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'x_array'},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'sort_x'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'expand'},{'id': '112', 'type': 'binary_operator', 'children': ['113', '117'], 'value': '*'},{'id': '113', 'type': 'list', 'children': ['114'], 'value': '[np.newaxis]'},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'newaxis'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '123']},{'id': '120', 'type': 'subscript', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'expand'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'slice'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'None', 'children': []},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'x_array'},{'id': '130', 'type': 'subscript', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'x_array'},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'expand'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'minv'},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'apply_along_axis'},{'id': '143', 'type': 'argument_list', 'children': ['144', '147', '148', '149']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'searchsorted'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'xp'},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'sort_x'},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'minv2'},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'minv'},{'id': '161', 'type': 'if_statement', 'children': ['162', '190']},{'id': '162', 'type': 'boolean_operator', 'children': ['163', '187'], 'value': 'and'},{'id': '163', 'type': '()', 'children': ['164']},{'id': '164', 'type': 'boolean_operator', 'children': ['165', '178'], 'value': 'or'},{'id': '165', 'type': '()', 'children': ['166']},{'id': '166', 'type': 'comparison_operator', 'children': ['167', '173'], 'value': '=='},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'minv'},{'id': '173', 'type': 'subscript', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'xp'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '178', 'type': '()', 'children': ['179']},{'id': '179', 'type': 'comparison_operator', 'children': ['180', '186'], 'value': '=='},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'minv'},{'id': '186', 'type': 'integer', 'children': [], 'value': '0'},{'id': '187', 'type': 'comparison_operator', 'children': ['188', '189'], 'value': 'is'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'fill_value'},{'id': '189', 'type': 'None', 'children': []},{'id': '190', 'type': 'block', 'children': ['191']},{'id': '191', 'type': 'raise_statement', 'children': ['192']},{'id': '192', 'type': 'call', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'string', 'children': [], 'value': "'Interpolation point out of data bounds encountered'"},{'id': '196', 'type': 'if_statement', 'children': ['197', '209']},{'id': '197', 'type': 'comparison_operator', 'children': ['198', '204'], 'value': '=='},{'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': 'max'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'minv'},{'id': '204', 'type': 'subscript', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'xp'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '209', 'type': 'block', 'children': ['210', '217']},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'call', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'warnings'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'string', 'children': [], 'value': "'Interpolation point out of data bounds encountered'"},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'assignment', 'children': ['219', '228']},{'id': '219', 'type': 'subscript', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'minv2'},{'id': '221', 'type': 'comparison_operator', 'children': ['222', '223'], 'value': '=='},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'minv'},{'id': '223', 'type': 'subscript', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'xp'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '228', 'type': 'binary_operator', 'children': ['229', '234'], 'value': '-'},{'id': '229', 'type': 'subscript', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'xp'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '234', 'type': 'integer', 'children': [], 'value': '1'},{'id': '235', 'type': 'if_statement', 'children': ['236', '244']},{'id': '236', 'type': 'comparison_operator', 'children': ['237', '243'], 'value': '=='},{'id': '237', 'type': 'call', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '241', 'type': 'argument_list', 'children': ['242']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'minv'},{'id': '243', 'type': 'integer', 'children': [], 'value': '0'},{'id': '244', 'type': 'block', 'children': ['245']},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'assignment', 'children': ['247', '252']},{'id': '247', 'type': 'subscript', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'minv2'},{'id': '249', 'type': 'comparison_operator', 'children': ['250', '251'], 'value': '=='},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'minv'},{'id': '251', 'type': 'integer', 'children': [], 'value': '0'},{'id': '252', 'type': 'integer', 'children': [], 'value': '1'},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'assignment', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'above'},{'id': '256', 'type': 'call', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'broadcast_indices'},{'id': '258', 'type': 'argument_list', 'children': ['259', '260', '261', '262']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'xp'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'minv2'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'assignment', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'below'},{'id': '266', 'type': 'call', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'broadcast_indices'},{'id': '268', 'type': 'argument_list', 'children': ['269', '270', '273', '274']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'xp'},{'id': '270', 'type': 'binary_operator', 'children': ['271', '272'], 'value': '-'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'minv2'},{'id': '272', 'type': 'integer', 'children': [], 'value': '1'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '275', 'type': 'if_statement', 'children': ['276', '286']},{'id': '276', 'type': 'call', 'children': ['277', '280']},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '280', 'type': 'argument_list', 'children': ['281']},{'id': '281', 'type': 'comparison_operator', 'children': ['282', '283'], 'value': '<'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'x_array'},{'id': '283', 'type': 'subscript', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'xp'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'below'},{'id': '286', 'type': 'block', 'children': ['287']},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'call', 'children': ['289', '292']},{'id': '289', 'type': 'attribute', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'warnings'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '292', 'type': 'argument_list', 'children': ['293']},{'id': '293', 'type': 'string', 'children': [], 'value': "'Interpolation point out of data bounds encountered'"},{'id': '294', 'type': 'expression_statement', 'children': ['295']},{'id': '295', 'type': 'assignment', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '297', 'type': 'list', 'children': [], 'value': '[]'},{'id': '298', 'type': 'for_statement', 'children': ['299', '300', '301']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'variables'},{'id': '301', 'type': 'block', 'children': ['302', '334', '346', '356', '390']},{'id': '302', 'type': 'expression_statement', 'children': ['303']},{'id': '303', 'type': 'assignment', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'var_interp'},{'id': '305', 'type': 'binary_operator', 'children': ['306', '309'], 'value': '+'},{'id': '306', 'type': 'subscript', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'below'},{'id': '309', 'type': 'binary_operator', 'children': ['310', '318'], 'value': '*'},{'id': '310', 'type': '()', 'children': ['311']},{'id': '311', 'type': 'binary_operator', 'children': ['312', '315'], 'value': '-'},{'id': '312', 'type': 'subscript', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'above'},{'id': '315', 'type': 'subscript', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'below'},{'id': '318', 'type': '()', 'children': ['319']},{'id': '319', 'type': 'binary_operator', 'children': ['320', '326'], 'value': '/'},{'id': '320', 'type': '()', 'children': ['321']},{'id': '321', 'type': 'binary_operator', 'children': ['322', '323'], 'value': '-'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'x_array'},{'id': '323', 'type': 'subscript', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'xp'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'below'},{'id': '326', 'type': '()', 'children': ['327']},{'id': '327', 'type': 'binary_operator', 'children': ['328', '331'], 'value': '-'},{'id': '328', 'type': 'subscript', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'xp'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'above'},{'id': '331', 'type': 'subscript', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'xp'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'below'},{'id': '334', 'type': 'expression_statement', 'children': ['335']},{'id': '335', 'type': 'assignment', 'children': ['336', '345']},{'id': '336', 'type': 'subscript', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'var_interp'},{'id': '338', 'type': 'comparison_operator', 'children': ['339', '340'], 'value': '=='},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'minv'},{'id': '340', 'type': 'subscript', 'children': ['341', '344']},{'id': '341', 'type': 'attribute', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'xp'},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'fill_value'},{'id': '346', 'type': 'expression_statement', 'children': ['347']},{'id': '347', 'type': 'assignment', 'children': ['348', '355']},{'id': '348', 'type': 'subscript', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'var_interp'},{'id': '350', 'type': 'comparison_operator', 'children': ['351', '352'], 'value': '<'},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'x_array'},{'id': '352', 'type': 'subscript', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'xp'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'below'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'fill_value'},{'id': '356', 'type': 'if_statement', 'children': ['357', '365']},{'id': '357', 'type': 'comparison_operator', 'children': ['358', '361'], 'value': '>'},{'id': '358', 'type': 'subscript', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '360', 'type': 'integer', 'children': [], 'value': '0'},{'id': '361', 'type': 'subscript', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '363', 'type': 'unary_operator', 'children': ['364'], 'value': '-'},{'id': '364', 'type': 'integer', 'children': [], 'value': '1'},{'id': '365', 'type': 'block', 'children': ['366']},{'id': '366', 'type': 'expression_statement', 'children': ['367']},{'id': '367', 'type': 'assignment', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'var_interp'},{'id': '369', 'type': 'call', 'children': ['370', '373']},{'id': '370', 'type': 'attribute', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'swapaxes'},{'id': '373', 'type': 'argument_list', 'children': ['374', '388', '389']},{'id': '374', 'type': 'subscript', 'children': ['375', '383']},{'id': '375', 'type': 'call', 'children': ['376', '379']},{'id': '376', 'type': 'attribute', 'children': ['377', '378']},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'swapaxes'},{'id': '379', 'type': 'argument_list', 'children': ['380', '381', '382']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'var_interp'},{'id': '381', 'type': 'integer', 'children': [], 'value': '0'},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '383', 'type': 'slice', 'children': ['384', '385', '386']},{'id': '384', 'type': 'colon', 'children': []},{'id': '385', 'type': 'colon', 'children': []},{'id': '386', 'type': 'unary_operator', 'children': ['387'], 'value': '-'},{'id': '387', 'type': 'integer', 'children': [], 'value': '1'},{'id': '388', 'type': 'integer', 'children': [], 'value': '0'},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '390', 'type': 'expression_statement', 'children': ['391']},{'id': '391', 'type': 'call', 'children': ['392', '395']},{'id': '392', 'type': 'attribute', 'children': ['393', '394']},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '395', 'type': 'argument_list', 'children': ['396']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'var_interp'},{'id': '397', 'type': 'if_statement', 'children': ['398', '404', '409']},{'id': '398', 'type': 'comparison_operator', 'children': ['399', '403'], 'value': '=='},{'id': '399', 'type': 'call', 'children': ['400', '401']},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '401', 'type': 'argument_list', 'children': ['402']},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '403', 'type': 'integer', 'children': [], 'value': '1'},{'id': '404', 'type': 'block', 'children': ['405']},{'id': '405', 'type': 'return_statement', 'children': ['406']},{'id': '406', 'type': 'subscript', 'children': ['407', '408']},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '408', 'type': 'integer', 'children': [], 'value': '0'},{'id': '409', 'type': 'else_clause', 'children': ['410']},{'id': '410', 'type': 'block', 'children': ['411']},{'id': '411', 'type': 'return_statement', 'children': ['412']},{'id': '412', 'type': 'identifier', 'children': [], 'value': 'ret'} | def interpolate_1d(x, xp, *args, **kwargs):
r
fill_value = kwargs.pop('fill_value', np.nan)
axis = kwargs.pop('axis', 0)
x = np.asanyarray(x).reshape(-1)
ndim = xp.ndim
sort_args = np.argsort(xp, axis=axis)
sort_x = np.argsort(x)
sorter = broadcast_indices(xp, sort_args, ndim, axis)
xp = xp[sorter]
variables = [arr[sorter] for arr in args]
x_array = x[sort_x]
expand = [np.newaxis] * ndim
expand[axis] = slice(None)
x_array = x_array[tuple(expand)]
minv = np.apply_along_axis(np.searchsorted, axis, xp, x[sort_x])
minv2 = np.copy(minv)
if ((np.max(minv) == xp.shape[axis]) or (np.min(minv) == 0)) and fill_value is None:
raise ValueError('Interpolation point out of data bounds encountered')
if np.max(minv) == xp.shape[axis]:
warnings.warn('Interpolation point out of data bounds encountered')
minv2[minv == xp.shape[axis]] = xp.shape[axis] - 1
if np.min(minv) == 0:
minv2[minv == 0] = 1
above = broadcast_indices(xp, minv2, ndim, axis)
below = broadcast_indices(xp, minv2 - 1, ndim, axis)
if np.any(x_array < xp[below]):
warnings.warn('Interpolation point out of data bounds encountered')
ret = []
for var in variables:
var_interp = var[below] + (var[above] - var[below]) * ((x_array - xp[below])
/ (xp[above] - xp[below]))
var_interp[minv == xp.shape[axis]] = fill_value
var_interp[x_array < xp[below]] = fill_value
if x[0] > x[-1]:
var_interp = np.swapaxes(np.swapaxes(var_interp, 0, axis)[::-1], 0, axis)
ret.append(var_interp)
if len(ret) == 1:
return ret[0]
else:
return ret |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'log_interpolate_1d'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'xp'},{'id': '6', 'type': 'list_splat_pattern', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '8', 'type': 'dictionary_splat_pattern', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '10', 'type': 'block', 'children': ['11', '13', '25', '35', '44', '53']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'fill_value'},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'string', 'children': [], 'value': "'fill_value'"},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'nan'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34']},{'id': '33', 'type': 'string', 'children': [], 'value': "'axis'"},{'id': '34', 'type': 'integer', 'children': [], 'value': '0'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'log_x'},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'log_xp'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'xp'},{'id': '53', 'type': 'return_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'interpolate_1d'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58', '59', '61', '64']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'log_x'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'log_xp'},{'id': '59', 'type': 'list_splat', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'fill_value'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'fill_value'} | def log_interpolate_1d(x, xp, *args, **kwargs):
r
fill_value = kwargs.pop('fill_value', np.nan)
axis = kwargs.pop('axis', 0)
log_x = np.log(x)
log_xp = np.log(xp)
return interpolate_1d(log_x, log_xp, *args, axis=axis, fill_value=fill_value) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_find_append_zero_crossings'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '6', 'type': 'block', 'children': ['7', '9', '39', '50', '61', '70', '76', '82', '97', '103', '109']},{'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': 'crossings'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'find_intersections'},{'id': '14', 'type': 'argument_list', 'children': ['15', '20', '25']},{'id': '15', 'type': 'subscript', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '17', 'type': 'slice', 'children': ['18', '19']},{'id': '18', 'type': 'integer', 'children': [], 'value': '1'},{'id': '19', 'type': 'colon', 'children': []},{'id': '20', 'type': 'subscript', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '22', 'type': 'slice', 'children': ['23', '24']},{'id': '23', 'type': 'integer', 'children': [], 'value': '1'},{'id': '24', 'type': 'colon', 'children': []},{'id': '25', 'type': 'binary_operator', 'children': ['26', '36'], 'value': '*'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'zeros_like'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'subscript', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '33', 'type': 'slice', 'children': ['34', '35']},{'id': '34', 'type': 'integer', 'children': [], 'value': '1'},{'id': '35', 'type': 'colon', 'children': []},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'concatenate'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'tuple', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'crossings'},{'id': '49', 'type': 'integer', 'children': [], 'value': '0'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'concatenate'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'tuple', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'crossings'},{'id': '60', 'type': 'integer', 'children': [], 'value': '1'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'sort_idx'},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '73', 'type': 'subscript', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'sort_idx'},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'sort_idx'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'keep_idx'},{'id': '85', 'type': 'comparison_operator', 'children': ['86', '96'], 'value': '>'},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'ediff1d'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'to_end'},{'id': '94', 'type': 'list', 'children': ['95'], 'value': '[1]'},{'id': '95', 'type': 'integer', 'children': [], 'value': '1'},{'id': '96', 'type': 'integer', 'children': [], 'value': '0'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '100', 'type': 'subscript', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'keep_idx'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'keep_idx'},{'id': '109', 'type': 'return_statement', 'children': ['110']},{'id': '110', 'type': 'expression_list', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'y'} | def _find_append_zero_crossings(x, y):
r
crossings = find_intersections(x[1:], y[1:], np.zeros_like(y[1:]) * y.units)
x = concatenate((x, crossings[0]))
y = concatenate((y, crossings[1]))
sort_idx = np.argsort(x)
x = x[sort_idx]
y = y[sort_idx]
keep_idx = np.ediff1d(x, to_end=[1]) > 0
x = x[keep_idx]
y = y[keep_idx]
return x, y |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_ordered_objects'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'getter'},{'id': '7', 'type': 'lambda', 'children': ['8', '10']},{'id': '8', 'type': 'lambda_parameters', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'return_statement', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '17', 'type': 'keyword_argument', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '19', 'type': 'lambda', 'children': ['20', '22']},{'id': '20', 'type': 'lambda_parameters', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '24', 'type': 'argument_list', 'children': ['25', '29', '32']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'getter'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'OrderedBase'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'CREATION_COUNTER_FIELD'},{'id': '32', 'type': 'unary_operator', 'children': ['33'], 'value': '-'},{'id': '33', 'type': 'integer', 'children': [], 'value': '1'} | def sort_ordered_objects(items, getter=lambda x: x):
return sorted(items, key=lambda x: getattr(getter(x), OrderedBase.CREATION_COUNTER_FIELD, -1)) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'remove_fewwords_paragraphs'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '23', '29']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'all_nodes'},{'id': '9', 'type': 'call', 'children': ['10', '15']},{'id': '10', 'type': 'attribute', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'getElementsByTags'},{'id': '15', 'type': 'argument_list', 'children': ['16', '21']},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'get_top_node'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'list', 'children': ['22'], 'value': "['*']"},{'id': '22', 'type': 'string', 'children': [], 'value': "'*'"},{'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': 'all_nodes'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '28', 'type': 'argument_list', 'children': []},{'id': '29', 'type': 'for_statement', 'children': ['30', '31', '32']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'all_nodes'},{'id': '32', 'type': 'block', 'children': ['33', '44', '55', '75']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '36', 'type': 'call', 'children': ['37', '42']},{'id': '37', 'type': 'attribute', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'getTag'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'text'},{'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': 'parser'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'getText'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'stop_words'},{'id': '58', 'type': 'call', 'children': ['59', '73']},{'id': '59', 'type': 'attribute', 'children': ['60', '72']},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'stopwords_class'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'get_language'},{'id': '71', 'type': 'argument_list', 'children': []},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'get_stopword_count'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '75', 'type': 'if_statement', 'children': ['76', '128', '138']},{'id': '76', 'type': 'boolean_operator', 'children': ['77', '111', '112'], 'value': 'and'},{'id': '77', 'type': 'boolean_operator', 'children': ['78', '94', '95'], 'value': 'and'},{'id': '78', 'type': 'boolean_operator', 'children': ['79', '87'], 'value': 'and'},{'id': '79', 'type': '()', 'children': ['80']},{'id': '80', 'type': 'boolean_operator', 'children': ['81', '84'], 'value': 'or'},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': '!='},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '83', 'type': 'string', 'children': [], 'value': "'br'"},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': '!='},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '86', 'type': 'string', 'children': [], 'value': "'\\\\r'"},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '93'], 'value': '<'},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'stop_words'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'get_stopword_count'},{'id': '92', 'type': 'argument_list', 'children': []},{'id': '93', 'type': 'integer', 'children': [], 'value': '3'},{'id': '94', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '110'], 'value': '=='},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '105']},{'id': '100', 'type': 'attribute', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'getElementsByTag'},{'id': '105', 'type': 'argument_list', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '109', 'type': 'string', 'children': [], 'value': "'object'"},{'id': '110', 'type': 'integer', 'children': [], 'value': '0'},{'id': '111', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '127'], 'value': '=='},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '122']},{'id': '117', 'type': 'attribute', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'getElementsByTag'},{'id': '122', 'type': 'argument_list', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '126', 'type': 'string', 'children': [], 'value': "'embed'"},{'id': '127', 'type': 'integer', 'children': [], 'value': '0'},{'id': '128', 'type': 'block', 'children': ['129']},{'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': 'parser'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '138', 'type': 'else_clause', 'children': ['139']},{'id': '139', 'type': 'block', 'children': ['140', '151']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'trimmed'},{'id': '143', 'type': 'call', 'children': ['144', '149']},{'id': '144', 'type': 'attribute', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'getText'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '151', 'type': 'if_statement', 'children': ['152', '165']},{'id': '152', 'type': 'boolean_operator', 'children': ['153', '159'], 'value': 'and'},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'trimmed'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'string', 'children': [], 'value': '"("'},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'trimmed'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'string', 'children': [], 'value': '")"'},{'id': '165', 'type': 'block', 'children': ['166']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'call', 'children': ['168', '173']},{'id': '168', 'type': 'attribute', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'el'} | def remove_fewwords_paragraphs(self):
all_nodes = self.parser.getElementsByTags(self.get_top_node(), ['*'])
all_nodes.reverse()
for el in all_nodes:
tag = self.parser.getTag(el)
text = self.parser.getText(el)
stop_words = self.stopwords_class(language=self.get_language()).get_stopword_count(text)
if (tag != 'br' or text != '\\r') and stop_words.get_stopword_count() < 3 \
and len(self.parser.getElementsByTag(el, tag='object')) == 0 \
and len(self.parser.getElementsByTag(el, tag='embed')) == 0:
self.parser.remove(el)
else:
trimmed = self.parser.getText(el)
if trimmed.startswith("(") and trimmed.endswith(")"):
self.parser.remove(el) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'compare_baselines'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'old_baseline_filename'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'new_baseline_filename'},{'id': '6', 'type': 'block', 'children': ['7', '14', '21', '28', '33', '38', '46', '53', '57', '64']},{'id': '7', 'type': 'if_statement', 'children': ['8', '11']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': '=='},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'old_baseline_filename'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'new_baseline_filename'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'raise_statement', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'RedundantComparisonError'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'old_baseline'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_get_baseline_from_file'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'old_baseline_filename'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'new_baseline'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': '_get_baseline_from_file'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'new_baseline_filename'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': '_remove_nonexistent_files_from_baseline'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'old_baseline'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_remove_nonexistent_files_from_baseline'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'new_baseline'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'secrets_to_compare'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': '_get_secrets_to_compare'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'old_baseline'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'new_baseline'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'total_reviews'},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'secrets_to_compare'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'current_index'},{'id': '56', 'type': 'integer', 'children': [], 'value': '0'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'secret_iterator'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'BidirectionalIterator'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'secrets_to_compare'},{'id': '64', 'type': 'for_statement', 'children': ['65', '69', '70']},{'id': '65', 'type': 'pattern_list', 'children': ['66', '67', '68']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'secret'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'is_removed'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'secret_iterator'},{'id': '70', 'type': 'block', 'children': ['71', '75', '79', '83', '154', '199', '210']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': '_clear_screen'},{'id': '74', 'type': 'argument_list', 'children': []},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'augmented_assignment', 'children': ['77', '78'], 'value': '+='},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'current_index'},{'id': '78', 'type': 'integer', 'children': [], 'value': '1'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '82', 'type': 'string', 'children': [], 'value': "'{} {}'"},{'id': '83', 'type': 'if_statement', 'children': ['84', '85', '119']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'is_removed'},{'id': '85', 'type': 'block', 'children': ['86', '92']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'plugins_used'},{'id': '89', 'type': 'subscript', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'old_baseline'},{'id': '91', 'type': 'string', 'children': [], 'value': "'plugins_used'"},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '99', 'type': 'argument_list', 'children': ['100', '107']},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'colorize'},{'id': '102', 'type': 'argument_list', 'children': ['103', '104']},{'id': '103', 'type': 'string', 'children': [], 'value': "'Status:'"},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'AnsiColor'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'BOLD'},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'string', 'children': [], 'value': "'>> {} <<'"},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'colorize'},{'id': '114', 'type': 'argument_list', 'children': ['115', '116']},{'id': '115', 'type': 'string', 'children': [], 'value': "'REMOVED'"},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'AnsiColor'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'RED'},{'id': '119', 'type': 'else_clause', 'children': ['120']},{'id': '120', 'type': 'block', 'children': ['121', '127']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'plugins_used'},{'id': '124', 'type': 'subscript', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'new_baseline'},{'id': '126', 'type': 'string', 'children': [], 'value': "'plugins_used'"},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '134', 'type': 'argument_list', 'children': ['135', '142']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'colorize'},{'id': '137', 'type': 'argument_list', 'children': ['138', '139']},{'id': '138', 'type': 'string', 'children': [], 'value': "'Status:'"},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'AnsiColor'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'BOLD'},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'string', 'children': [], 'value': "'>> {} <<'"},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'colorize'},{'id': '149', 'type': 'argument_list', 'children': ['150', '151']},{'id': '150', 'type': 'string', 'children': [], 'value': "'ADDED'"},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'AnsiColor'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'LIGHT_GREEN'},{'id': '154', 'type': 'try_statement', 'children': ['155', '187']},{'id': '155', 'type': 'block', 'children': ['156', '171']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': '_print_context'},{'id': '159', 'type': 'argument_list', 'children': ['160', '161', '162', '163', '164', '165', '168']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'secret'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'current_index'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'total_reviews'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'plugins_used'},{'id': '165', 'type': 'keyword_argument', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'additional_header_lines'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '168', 'type': 'keyword_argument', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'force'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'is_removed'},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'decision'},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': '_get_user_decision'},{'id': '176', 'type': 'argument_list', 'children': ['177', '184']},{'id': '177', 'type': 'keyword_argument', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'can_step_back'},{'id': '179', 'type': 'call', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'secret_iterator'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'can_step_back'},{'id': '183', 'type': 'argument_list', 'children': []},{'id': '184', 'type': 'keyword_argument', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'prompt_secret_decision'},{'id': '186', 'type': 'False', 'children': []},{'id': '187', 'type': 'except_clause', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'SecretNotFoundOnSpecifiedLineError'},{'id': '189', 'type': 'block', 'children': ['190']},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'decision'},{'id': '193', 'type': 'call', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': '_get_user_decision'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'keyword_argument', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'prompt_secret_decision'},{'id': '198', 'type': 'False', 'children': []},{'id': '199', 'type': 'if_statement', 'children': ['200', '203']},{'id': '200', 'type': 'comparison_operator', 'children': ['201', '202'], 'value': '=='},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'decision'},{'id': '202', 'type': 'string', 'children': [], 'value': "'q'"},{'id': '203', 'type': 'block', 'children': ['204', '209']},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'string', 'children': [], 'value': "'Quitting...'"},{'id': '209', 'type': 'break_statement', 'children': []},{'id': '210', 'type': 'if_statement', 'children': ['211', '214']},{'id': '211', 'type': 'comparison_operator', 'children': ['212', '213'], 'value': '=='},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'decision'},{'id': '213', 'type': 'string', 'children': [], 'value': "'b'"},{'id': '214', 'type': 'block', 'children': ['215', '219']},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'augmented_assignment', 'children': ['217', '218'], 'value': '-='},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'current_index'},{'id': '218', 'type': 'integer', 'children': [], 'value': '2'},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'secret_iterator'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'step_back_on_next_iteration'},{'id': '224', 'type': 'argument_list', 'children': []} | def compare_baselines(old_baseline_filename, new_baseline_filename):
if old_baseline_filename == new_baseline_filename:
raise RedundantComparisonError
old_baseline = _get_baseline_from_file(old_baseline_filename)
new_baseline = _get_baseline_from_file(new_baseline_filename)
_remove_nonexistent_files_from_baseline(old_baseline)
_remove_nonexistent_files_from_baseline(new_baseline)
secrets_to_compare = _get_secrets_to_compare(old_baseline, new_baseline)
total_reviews = len(secrets_to_compare)
current_index = 0
secret_iterator = BidirectionalIterator(secrets_to_compare)
for filename, secret, is_removed in secret_iterator:
_clear_screen()
current_index += 1
header = '{} {}'
if is_removed:
plugins_used = old_baseline['plugins_used']
header = header.format(
colorize('Status:', AnsiColor.BOLD),
'>> {} <<'.format(
colorize('REMOVED', AnsiColor.RED),
),
)
else:
plugins_used = new_baseline['plugins_used']
header = header.format(
colorize('Status:', AnsiColor.BOLD),
'>> {} <<'.format(
colorize('ADDED', AnsiColor.LIGHT_GREEN),
),
)
try:
_print_context(
filename,
secret,
current_index,
total_reviews,
plugins_used,
additional_header_lines=header,
force=is_removed,
)
decision = _get_user_decision(
can_step_back=secret_iterator.can_step_back(),
prompt_secret_decision=False,
)
except SecretNotFoundOnSpecifiedLineError:
decision = _get_user_decision(prompt_secret_decision=False)
if decision == 'q':
print('Quitting...')
break
if decision == 'b':
current_index -= 2
secret_iterator.step_back_on_next_iteration() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_GetEventIdentifiers'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '6', 'type': 'block', 'children': ['7', '11', '22', '29', '151', '189', '199', '208']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '10', 'type': 'list', 'children': [], 'value': '[]'},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'attribute_string'},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'string', 'children': [], 'value': "'data_type: {0:s}'"},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'data_type'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'attribute_string'},{'id': '29', 'type': 'for_statement', 'children': ['30', '33', '41']},{'id': '30', 'type': 'pattern_list', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'attribute_name'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'attribute_value'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'GetAttributes'},{'id': '40', 'type': 'argument_list', 'children': []},{'id': '41', 'type': 'block', 'children': ['42', '50', '55', '117', '144']},{'id': '42', 'type': 'if_statement', 'children': ['43', '48']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': 'in'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'attribute_name'},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': '_IDENTIFIER_EXCLUDED_ATTRIBUTES'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'continue_statement', 'children': []},{'id': '50', 'type': 'if_statement', 'children': ['51', '53']},{'id': '51', 'type': 'not_operator', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'attribute_value'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'continue_statement', 'children': []},{'id': '55', 'type': 'if_statement', 'children': ['56', '59', '66', '84', '101']},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': '=='},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'attribute_name'},{'id': '58', 'type': 'string', 'children': [], 'value': "'pathspec'"},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'attribute_value'},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'attribute_value'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'comparable'},{'id': '66', 'type': 'elif_clause', 'children': ['67', '72']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'attribute_value'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'attribute_value'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'attribute_value'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '83', 'type': 'argument_list', 'children': []},{'id': '84', 'type': 'elif_clause', 'children': ['85', '90']},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '87', 'type': 'argument_list', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'attribute_value'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'attribute_value'},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'attribute_value'},{'id': '101', 'type': 'elif_clause', 'children': ['102', '109']},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '104', 'type': 'argument_list', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'attribute_value'},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'py2to3'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'BYTES_TYPE'},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'attribute_value'},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'repr'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'attribute_value'},{'id': '117', 'type': 'try_statement', 'children': ['118', '129']},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'attribute_string'},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'string', 'children': [], 'value': "'{0:s}: {1!s}'"},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '126', 'type': 'argument_list', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'attribute_name'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'attribute_value'},{'id': '129', 'type': 'except_clause', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'UnicodeDecodeError'},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'string', 'children': [], 'value': "'Failed to decode attribute {0:s}'"},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'attribute_name'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'attribute_string'},{'id': '151', 'type': 'if_statement', 'children': ['152', '173', '183']},{'id': '152', 'type': 'comparison_operator', 'children': ['153', '156'], 'value': 'in'},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'timestamp_desc'},{'id': '156', 'type': 'tuple', 'children': ['157', '158', '159', '160', '161', '164', '167', '170']},{'id': '157', 'type': 'string', 'children': [], 'value': "'atime'"},{'id': '158', 'type': 'string', 'children': [], 'value': "'ctime'"},{'id': '159', 'type': 'string', 'children': [], 'value': "'crtime'"},{'id': '160', 'type': 'string', 'children': [], 'value': "'mtime'"},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'definitions'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'TIME_DESCRIPTION_LAST_ACCESS'},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'definitions'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'TIME_DESCRIPTION_CHANGE'},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'definitions'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'TIME_DESCRIPTION_CREATION'},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'definitions'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'TIME_DESCRIPTION_MODIFICATION'},{'id': '173', 'type': 'block', 'children': ['174']},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'macb_group_identifier'},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'string', 'children': [], 'value': "', '"},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'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', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'macb_group_identifier'},{'id': '188', 'type': 'None', 'children': []},{'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': 'attributes'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '194', 'type': 'argument_list', 'children': ['195', '196']},{'id': '195', 'type': 'integer', 'children': [], 'value': '0'},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'timestamp_desc'},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'content_identifier'},{'id': '202', 'type': 'call', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'string', 'children': [], 'value': "', '"},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '208', 'type': 'return_statement', 'children': ['209']},{'id': '209', 'type': 'expression_list', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'macb_group_identifier'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'content_identifier'} | def _GetEventIdentifiers(self, event):
attributes = []
attribute_string = 'data_type: {0:s}'.format(event.data_type)
attributes.append(attribute_string)
for attribute_name, attribute_value in sorted(event.GetAttributes()):
if attribute_name in self._IDENTIFIER_EXCLUDED_ATTRIBUTES:
continue
if not attribute_value:
continue
if attribute_name == 'pathspec':
attribute_value = attribute_value.comparable
elif isinstance(attribute_value, dict):
attribute_value = sorted(attribute_value.items())
elif isinstance(attribute_value, set):
attribute_value = sorted(list(attribute_value))
elif isinstance(attribute_value, py2to3.BYTES_TYPE):
attribute_value = repr(attribute_value)
try:
attribute_string = '{0:s}: {1!s}'.format(
attribute_name, attribute_value)
except UnicodeDecodeError:
logger.error('Failed to decode attribute {0:s}'.format(
attribute_name))
attributes.append(attribute_string)
if event.timestamp_desc in (
'atime', 'ctime', 'crtime', 'mtime',
definitions.TIME_DESCRIPTION_LAST_ACCESS,
definitions.TIME_DESCRIPTION_CHANGE,
definitions.TIME_DESCRIPTION_CREATION,
definitions.TIME_DESCRIPTION_MODIFICATION):
macb_group_identifier = ', '.join(attributes)
else:
macb_group_identifier = None
attributes.insert(0, event.timestamp_desc)
content_identifier = ', '.join(attributes)
return macb_group_identifier, content_identifier |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'PopEvents'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '14']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'event'},{'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': 'PopEvent'},{'id': '13', 'type': 'argument_list', 'children': []},{'id': '14', 'type': 'while_statement', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '16', 'type': 'block', 'children': ['17', '20']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'yield', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'event'},{'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': 'PopEvent'},{'id': '27', 'type': 'argument_list', 'children': []} | def PopEvents(self):
event = self.PopEvent()
while event:
yield event
event = self.PopEvent() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_CheckStatusAnalysisProcess'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'pid'},{'id': '6', 'type': 'block', 'children': ['7', '14', '264', '273']},{'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': '_RaiseIfNotRegistered'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'pid'},{'id': '14', 'type': 'if_statement', 'children': ['15', '20', '38']},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'in'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'pid'},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': '_completed_analysis_processes'},{'id': '20', 'type': 'block', 'children': ['21', '27', '34']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'status_indicator'},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'definitions'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'STATUS_INDICATOR_COMPLETED'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'process_status'},{'id': '30', 'type': 'dictionary', 'children': ['31']},{'id': '31', 'type': 'pair', 'children': ['32', '33']},{'id': '32', 'type': 'string', 'children': [], 'value': "'processing_status'"},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'status_indicator'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'used_memory'},{'id': '37', 'type': 'integer', 'children': [], 'value': '0'},{'id': '38', 'type': 'else_clause', 'children': ['39']},{'id': '39', 'type': 'block', 'children': ['40', '48', '57', '72', '80', '90', '129']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '43', 'type': 'subscript', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': '_processes_per_pid'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'pid'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'process_status'},{'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': '_QueryProcessStatus'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '57', 'type': 'if_statement', 'children': ['58', '61', '66']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'is'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'process_status'},{'id': '60', 'type': 'None', 'children': []},{'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': 'process_is_alive'},{'id': '65', 'type': 'False', 'children': []},{'id': '66', 'type': 'else_clause', 'children': ['67']},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'process_is_alive'},{'id': '71', 'type': 'True', 'children': []},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'process_information'},{'id': '75', 'type': 'subscript', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '78', 'type': 'identifier', 'children': [], 'value': '_process_information_per_pid'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'pid'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'used_memory'},{'id': '83', 'type': 'boolean_operator', 'children': ['84', '89'], 'value': 'or'},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'process_information'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'GetUsedMemory'},{'id': '88', 'type': 'argument_list', 'children': []},{'id': '89', 'type': 'integer', 'children': [], 'value': '0'},{'id': '90', 'type': 'if_statement', 'children': ['91', '100']},{'id': '91', 'type': 'boolean_operator', 'children': ['92', '95'], 'value': 'and'},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '94', 'type': 'identifier', 'children': [], 'value': '_worker_memory_limit'},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': '>'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'used_memory'},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': '_worker_memory_limit'},{'id': '100', 'type': 'block', 'children': ['101', '122']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '114']},{'id': '108', 'type': 'attribute', 'children': ['109', '113']},{'id': '109', 'type': '()', 'children': ['110']},{'id': '110', 'type': 'concatenated_string', 'children': ['111', '112']},{'id': '111', 'type': 'string', 'children': [], 'value': "'Process: {0:s} (PID: {1:d}) killed because it exceeded the '"},{'id': '112', 'type': 'string', 'children': [], 'value': "'memory limit: {2:d}.'"},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '114', 'type': 'argument_list', 'children': ['115', '118', '119']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'pid'},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'identifier', 'children': [], 'value': '_worker_memory_limit'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '126', 'type': 'identifier', 'children': [], 'value': '_KillProcess'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'pid'},{'id': '129', 'type': 'if_statement', 'children': ['130', '135', '170']},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '132', 'type': 'argument_list', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'process_status'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '135', 'type': 'block', 'children': ['136', '144', '154']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '143']},{'id': '138', 'type': 'subscript', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '141', 'type': 'identifier', 'children': [], 'value': '_rpc_errors_per_pid'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'pid'},{'id': '143', 'type': 'integer', 'children': [], 'value': '0'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'status_indicator'},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'process_status'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '151', 'type': 'argument_list', 'children': ['152', '153']},{'id': '152', 'type': 'string', 'children': [], 'value': "'processing_status'"},{'id': '153', 'type': 'None', 'children': []},{'id': '154', 'type': 'if_statement', 'children': ['155', '160']},{'id': '155', 'type': 'comparison_operator', 'children': ['156', '157'], 'value': '=='},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'status_indicator'},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'definitions'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'STATUS_INDICATOR_COMPLETED'},{'id': '160', 'type': 'block', 'children': ['161']},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'call', 'children': ['163', '168']},{'id': '163', 'type': 'attribute', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '166', 'type': 'identifier', 'children': [], 'value': '_completed_analysis_processes'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'pid'},{'id': '170', 'type': 'else_clause', 'children': ['171']},{'id': '171', 'type': 'block', 'children': ['172', '186', '194', '205', '257']},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'rpc_errors'},{'id': '175', 'type': 'binary_operator', 'children': ['176', '185'], 'value': '+'},{'id': '176', 'type': 'call', 'children': ['177', '182']},{'id': '177', 'type': 'attribute', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '180', 'type': 'identifier', 'children': [], 'value': '_rpc_errors_per_pid'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '182', 'type': 'argument_list', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'pid'},{'id': '184', 'type': 'integer', 'children': [], 'value': '0'},{'id': '185', 'type': 'integer', 'children': [], 'value': '1'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '193']},{'id': '188', 'type': 'subscript', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '191', 'type': 'identifier', 'children': [], 'value': '_rpc_errors_per_pid'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'pid'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'rpc_errors'},{'id': '194', 'type': 'if_statement', 'children': ['195', '200']},{'id': '195', 'type': 'comparison_operator', 'children': ['196', '197'], 'value': '>'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'rpc_errors'},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '199', 'type': 'identifier', 'children': [], 'value': '_MAXIMUM_RPC_ERRORS'},{'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': 'process_is_alive'},{'id': '204', 'type': 'False', 'children': []},{'id': '205', 'type': 'if_statement', 'children': ['206', '207', '245']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'process_is_alive'},{'id': '207', 'type': 'block', 'children': ['208', '216', '235', '239']},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'assignment', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'rpc_port'},{'id': '211', 'type': 'attribute', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'rpc_port'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'call', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '229']},{'id': '223', 'type': 'attribute', 'children': ['224', '228']},{'id': '224', 'type': '()', 'children': ['225']},{'id': '225', 'type': 'concatenated_string', 'children': ['226', '227']},{'id': '226', 'type': 'string', 'children': [], 'value': "'Unable to retrieve process: {0:s} (PID: {1:d}) status via '"},{'id': '227', 'type': 'string', 'children': [], 'value': "'RPC socket: http://localhost:{2:d}'"},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '229', 'type': 'argument_list', 'children': ['230', '233', '234']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'pid'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'rpc_port'},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'processing_status_string'},{'id': '238', 'type': 'string', 'children': [], 'value': "'RPC error'"},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'assignment', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'status_indicator'},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'definitions'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'STATUS_INDICATOR_RUNNING'},{'id': '245', 'type': 'else_clause', 'children': ['246']},{'id': '246', 'type': 'block', 'children': ['247', '251']},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'assignment', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'processing_status_string'},{'id': '250', 'type': 'string', 'children': [], 'value': "'killed'"},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'assignment', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'status_indicator'},{'id': '254', 'type': 'attribute', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'definitions'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'STATUS_INDICATOR_KILLED'},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'assignment', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'process_status'},{'id': '260', 'type': 'dictionary', 'children': ['261']},{'id': '261', 'type': 'pair', 'children': ['262', '263']},{'id': '262', 'type': 'string', 'children': [], 'value': "'processing_status'"},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'processing_status_string'},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'call', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '268', 'type': 'identifier', 'children': [], 'value': '_UpdateProcessingStatus'},{'id': '269', 'type': 'argument_list', 'children': ['270', '271', '272']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'pid'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'process_status'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'used_memory'},{'id': '273', 'type': 'if_statement', 'children': ['274', '279']},{'id': '274', 'type': 'comparison_operator', 'children': ['275', '276'], 'value': 'in'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'status_indicator'},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'definitions'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'ERROR_STATUS_INDICATORS'},{'id': '279', 'type': 'block', 'children': ['280', '299']},{'id': '280', 'type': 'expression_statement', 'children': ['281']},{'id': '281', 'type': 'call', 'children': ['282', '285']},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '285', 'type': 'argument_list', 'children': ['286']},{'id': '286', 'type': 'call', 'children': ['287', '293']},{'id': '287', 'type': 'attribute', 'children': ['288', '292']},{'id': '288', 'type': '()', 'children': ['289']},{'id': '289', 'type': 'concatenated_string', 'children': ['290', '291']},{'id': '290', 'type': 'string', 'children': [], 'value': "'Process {0:s} (PID: {1:d}) is not functioning correctly. '"},{'id': '291', 'type': 'string', 'children': [], 'value': "'Status code: {2!s}.'"},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '293', 'type': 'argument_list', 'children': ['294', '297', '298']},{'id': '294', 'type': 'attribute', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'pid'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'status_indicator'},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'call', 'children': ['301', '304']},{'id': '301', 'type': 'attribute', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '303', 'type': 'identifier', 'children': [], 'value': '_TerminateProcessByPid'},{'id': '304', 'type': 'argument_list', 'children': ['305']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'pid'} | def _CheckStatusAnalysisProcess(self, pid):
self._RaiseIfNotRegistered(pid)
if pid in self._completed_analysis_processes:
status_indicator = definitions.STATUS_INDICATOR_COMPLETED
process_status = {
'processing_status': status_indicator}
used_memory = 0
else:
process = self._processes_per_pid[pid]
process_status = self._QueryProcessStatus(process)
if process_status is None:
process_is_alive = False
else:
process_is_alive = True
process_information = self._process_information_per_pid[pid]
used_memory = process_information.GetUsedMemory() or 0
if self._worker_memory_limit and used_memory > self._worker_memory_limit:
logger.warning((
'Process: {0:s} (PID: {1:d}) killed because it exceeded the '
'memory limit: {2:d}.').format(
process.name, pid, self._worker_memory_limit))
self._KillProcess(pid)
if isinstance(process_status, dict):
self._rpc_errors_per_pid[pid] = 0
status_indicator = process_status.get('processing_status', None)
if status_indicator == definitions.STATUS_INDICATOR_COMPLETED:
self._completed_analysis_processes.add(pid)
else:
rpc_errors = self._rpc_errors_per_pid.get(pid, 0) + 1
self._rpc_errors_per_pid[pid] = rpc_errors
if rpc_errors > self._MAXIMUM_RPC_ERRORS:
process_is_alive = False
if process_is_alive:
rpc_port = process.rpc_port.value
logger.warning((
'Unable to retrieve process: {0:s} (PID: {1:d}) status via '
'RPC socket: http://localhost:{2:d}').format(
process.name, pid, rpc_port))
processing_status_string = 'RPC error'
status_indicator = definitions.STATUS_INDICATOR_RUNNING
else:
processing_status_string = 'killed'
status_indicator = definitions.STATUS_INDICATOR_KILLED
process_status = {
'processing_status': processing_status_string}
self._UpdateProcessingStatus(pid, process_status, used_memory)
if status_indicator in definitions.ERROR_STATUS_INDICATORS:
logger.error((
'Process {0:s} (PID: {1:d}) is not functioning correctly. '
'Status code: {2!s}.').format(
process.name, pid, status_indicator))
self._TerminateProcessByPid(pid) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_ExportEvent'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'output_module'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'deduplicate_events'},{'id': '9', 'type': 'True', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '38']},{'id': '11', 'type': 'if_statement', 'children': ['12', '19']},{'id': '12', 'type': 'comparison_operator', 'children': ['13', '16'], 'value': '!='},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'timestamp'},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_export_event_timestamp'},{'id': '19', 'type': 'block', 'children': ['20', '30']},{'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': '_FlushExportBuffer'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'output_module'},{'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'deduplicate_events'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'deduplicate_events'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': '_export_event_timestamp'},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'timestamp'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '45']},{'id': '40', 'type': 'attribute', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': '_export_event_heap'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'PushEvent'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'event'} | def _ExportEvent(self, output_module, event, deduplicate_events=True):
if event.timestamp != self._export_event_timestamp:
self._FlushExportBuffer(
output_module, deduplicate_events=deduplicate_events)
self._export_event_timestamp = event.timestamp
self._export_event_heap.PushEvent(event) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_FlushExportBuffer'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'output_module'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'deduplicate_events'},{'id': '8', 'type': 'True', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '14', '18', '22', '32', '129']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'last_macb_group_identifier'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'last_content_identifier'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'macb_group'},{'id': '21', 'type': 'list', 'children': [], 'value': '[]'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'generator'},{'id': '25', 'type': 'call', 'children': ['26', '31']},{'id': '26', 'type': 'attribute', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_export_event_heap'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'PopEvents'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'for_statement', 'children': ['33', '37', '38']},{'id': '33', 'type': 'pattern_list', 'children': ['34', '35', '36']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'macb_group_identifier'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'content_identifier'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'generator'},{'id': '38', 'type': 'block', 'children': ['39', '55', '121', '125']},{'id': '39', 'type': 'if_statement', 'children': ['40', '45']},{'id': '40', 'type': 'boolean_operator', 'children': ['41', '42'], 'value': 'and'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'deduplicate_events'},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': '=='},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'last_content_identifier'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'content_identifier'},{'id': '45', 'type': 'block', 'children': ['46', '54']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'augmented_assignment', 'children': ['48', '53'], 'value': '+='},{'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': '_events_status'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'number_of_duplicate_events'},{'id': '53', 'type': 'integer', 'children': [], 'value': '1'},{'id': '54', 'type': 'continue_statement', 'children': []},{'id': '55', 'type': 'if_statement', 'children': ['56', '59', '81']},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'is'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'macb_group_identifier'},{'id': '58', 'type': 'None', 'children': []},{'id': '59', 'type': 'block', 'children': ['60', '74']},{'id': '60', 'type': 'if_statement', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'macb_group'},{'id': '62', 'type': 'block', 'children': ['63', '70']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'output_module'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'WriteEventMACBGroup'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'macb_group'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'macb_group'},{'id': '73', 'type': 'list', 'children': [], 'value': '[]'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'output_module'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'WriteEvent'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '81', 'type': 'else_clause', 'children': ['82']},{'id': '82', 'type': 'block', 'children': ['83', '113']},{'id': '83', 'type': 'if_statement', 'children': ['84', '91', '99']},{'id': '84', 'type': '()', 'children': ['85']},{'id': '85', 'type': 'boolean_operator', 'children': ['86', '89'], 'value': 'or'},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': '=='},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'last_macb_group_identifier'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'macb_group_identifier'},{'id': '89', 'type': 'not_operator', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'macb_group'},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'macb_group'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '99', 'type': 'else_clause', 'children': ['100']},{'id': '100', 'type': 'block', 'children': ['101', '108']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'output_module'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'WriteEventMACBGroup'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'macb_group'},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'macb_group'},{'id': '111', 'type': 'list', 'children': ['112'], 'value': '[event]'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'augmented_assignment', 'children': ['115', '120'], 'value': '+='},{'id': '115', 'type': 'attribute', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '118', 'type': 'identifier', 'children': [], 'value': '_events_status'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'number_of_macb_grouped_events'},{'id': '120', 'type': 'integer', 'children': [], 'value': '1'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'last_macb_group_identifier'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'macb_group_identifier'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'last_content_identifier'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'content_identifier'},{'id': '129', 'type': 'if_statement', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'macb_group'},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'output_module'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'WriteEventMACBGroup'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'macb_group'} | def _FlushExportBuffer(self, output_module, deduplicate_events=True):
last_macb_group_identifier = None
last_content_identifier = None
macb_group = []
generator = self._export_event_heap.PopEvents()
for macb_group_identifier, content_identifier, event in generator:
if deduplicate_events and last_content_identifier == content_identifier:
self._events_status.number_of_duplicate_events += 1
continue
if macb_group_identifier is None:
if macb_group:
output_module.WriteEventMACBGroup(macb_group)
macb_group = []
output_module.WriteEvent(event)
else:
if (last_macb_group_identifier == macb_group_identifier or
not macb_group):
macb_group.append(event)
else:
output_module.WriteEventMACBGroup(macb_group)
macb_group = [event]
self._events_status.number_of_macb_grouped_events += 1
last_macb_group_identifier = macb_group_identifier
last_content_identifier = content_identifier
if macb_group:
output_module.WriteEventMACBGroup(macb_group) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_MergeEventTag'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'storage_writer'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'attribute_container'},{'id': '7', 'type': 'block', 'children': ['8', '16', '24', '29', '41', '62']},{'id': '8', 'type': 'if_statement', 'children': ['9', '14']},{'id': '9', 'type': 'comparison_operator', 'children': ['10', '13'], 'value': '!='},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'attribute_container'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'CONTAINER_TYPE'},{'id': '13', 'type': 'string', 'children': [], 'value': "'event_tag'"},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'return_statement', 'children': []},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'event_identifier'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'attribute_container'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'GetEventIdentifier'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'if_statement', 'children': ['25', '27']},{'id': '25', 'type': 'not_operator', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'event_identifier'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'return_statement', 'children': []},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'stored_event_tag'},{'id': '32', 'type': 'call', 'children': ['33', '38']},{'id': '33', 'type': 'attribute', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': '_event_tag_index'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'GetEventTagByIdentifier'},{'id': '38', 'type': 'argument_list', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'storage_writer'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'event_identifier'},{'id': '41', 'type': 'if_statement', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'stored_event_tag'},{'id': '43', 'type': 'block', 'children': ['44', '53']},{'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': 'attribute_container'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'AddComment'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'stored_event_tag'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'comment'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'attribute_container'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'AddLabels'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'stored_event_tag'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'labels'},{'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': '_event_tag_index'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'SetEventTag'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'attribute_container'} | def _MergeEventTag(self, storage_writer, attribute_container):
if attribute_container.CONTAINER_TYPE != 'event_tag':
return
event_identifier = attribute_container.GetEventIdentifier()
if not event_identifier:
return
stored_event_tag = self._event_tag_index.GetEventTagByIdentifier(
storage_writer, event_identifier)
if stored_event_tag:
attribute_container.AddComment(stored_event_tag.comment)
attribute_container.AddLabels(stored_event_tag.labels)
self._event_tag_index.SetEventTag(attribute_container) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_StartAnalysisProcesses'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'storage_writer'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'analysis_plugins'},{'id': '7', 'type': 'block', 'children': ['8', '15', '63']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'string', 'children': [], 'value': "'Starting analysis plugins.'"},{'id': '15', 'type': 'for_statement', 'children': ['16', '17', '22']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'analysis_plugin'},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'analysis_plugins'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '21', 'type': 'argument_list', 'children': []},{'id': '22', 'type': 'block', 'children': ['23', '33', '45']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '32']},{'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': '_analysis_plugins'},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'analysis_plugin'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'NAME'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'analysis_plugin'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': '_StartWorkerProcess'},{'id': '40', 'type': 'argument_list', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'analysis_plugin'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'NAME'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'storage_writer'},{'id': '45', 'type': 'if_statement', 'children': ['46', '48']},{'id': '46', 'type': 'not_operator', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '48', 'type': 'block', 'children': ['49']},{'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': 'logger'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'string', 'children': [], 'value': "'Unable to create analysis process: {0:s}'"},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'analysis_plugin'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'NAME'},{'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': 'logger'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'string', 'children': [], 'value': "'Analysis plugins running'"} | def _StartAnalysisProcesses(self, storage_writer, analysis_plugins):
logger.info('Starting analysis plugins.')
for analysis_plugin in analysis_plugins.values():
self._analysis_plugins[analysis_plugin.NAME] = analysis_plugin
process = self._StartWorkerProcess(analysis_plugin.NAME, storage_writer)
if not process:
logger.error('Unable to create analysis process: {0:s}'.format(
analysis_plugin.NAME))
logger.info('Analysis plugins running') |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_StopAnalysisProcesses'},{'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': 'abort'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '16', '22', '31', '60', '84', '95', '114']},{'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': 'logger'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'string', 'children': [], 'value': "'Stopping analysis processes.'"},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'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': '_StopMonitoringProcesses'},{'id': '21', 'type': 'argument_list', 'children': []},{'id': '22', 'type': 'if_statement', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'abort'},{'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': '_AbortTerminate'},{'id': '30', 'type': 'argument_list', 'children': []},{'id': '31', 'type': 'if_statement', 'children': ['32', '36']},{'id': '32', 'type': 'not_operator', 'children': ['33']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_use_zeromq'},{'id': '36', 'type': 'block', 'children': ['37', '44']},{'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': 'logger'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'string', 'children': [], 'value': "'Emptying queues.'"},{'id': '44', 'type': 'for_statement', 'children': ['45', '46', '53']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'event_queue'},{'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': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': '_event_queues'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '52', 'type': 'argument_list', 'children': []},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'event_queue'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'Empty'},{'id': '59', 'type': 'argument_list', 'children': []},{'id': '60', 'type': 'for_statement', 'children': ['61', '62', '69']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'event_queue'},{'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': '_event_queues'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '68', 'type': 'argument_list', 'children': []},{'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': 'event_queue'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'PushItem'},{'id': '75', 'type': 'argument_list', 'children': ['76', '81']},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'plaso_queue'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'QueueAbort'},{'id': '80', 'type': 'argument_list', 'children': []},{'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '83', 'type': 'False', 'children': []},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': '_AbortJoin'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '94', 'type': 'identifier', 'children': [], 'value': '_PROCESS_JOIN_TIMEOUT'},{'id': '95', 'type': 'for_statement', 'children': ['96', '97', '104']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'event_queue'},{'id': '97', 'type': 'call', 'children': ['98', '103']},{'id': '98', 'type': 'attribute', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '101', 'type': 'identifier', 'children': [], 'value': '_event_queues'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '103', 'type': 'argument_list', 'children': []},{'id': '104', 'type': 'block', 'children': ['105']},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'event_queue'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'Close'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'keyword_argument', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'abort'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'abort'},{'id': '114', 'type': 'if_statement', 'children': ['115', '116', '123']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'abort'},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'identifier', 'children': [], 'value': '_AbortKill'},{'id': '122', 'type': 'argument_list', 'children': []},{'id': '123', 'type': 'else_clause', 'children': ['124']},{'id': '124', 'type': 'block', 'children': ['125', '131', '142']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '129', 'type': 'identifier', 'children': [], 'value': '_AbortTerminate'},{'id': '130', 'type': 'argument_list', 'children': []},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '135', 'type': 'identifier', 'children': [], 'value': '_AbortJoin'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '141', 'type': 'identifier', 'children': [], 'value': '_PROCESS_JOIN_TIMEOUT'},{'id': '142', 'type': 'for_statement', 'children': ['143', '144', '151']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'event_queue'},{'id': '144', 'type': 'call', 'children': ['145', '150']},{'id': '145', 'type': 'attribute', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '148', 'type': 'identifier', 'children': [], 'value': '_event_queues'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '150', 'type': 'argument_list', 'children': []},{'id': '151', 'type': 'block', 'children': ['152']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'event_queue'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'Close'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'abort'},{'id': '160', 'type': 'True', 'children': []} | def _StopAnalysisProcesses(self, abort=False):
logger.debug('Stopping analysis processes.')
self._StopMonitoringProcesses()
if abort:
self._AbortTerminate()
if not self._use_zeromq:
logger.debug('Emptying queues.')
for event_queue in self._event_queues.values():
event_queue.Empty()
for event_queue in self._event_queues.values():
event_queue.PushItem(plaso_queue.QueueAbort(), block=False)
self._AbortJoin(timeout=self._PROCESS_JOIN_TIMEOUT)
for event_queue in self._event_queues.values():
event_queue.Close(abort=abort)
if abort:
self._AbortKill()
else:
self._AbortTerminate()
self._AbortJoin(timeout=self._PROCESS_JOIN_TIMEOUT)
for event_queue in self._event_queues.values():
event_queue.Close(abort=True) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_UpdateForemanProcessStatus'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '18', '29', '78']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'used_memory'},{'id': '9', 'type': 'boolean_operator', 'children': ['10', '17'], 'value': 'or'},{'id': '10', 'type': 'call', 'children': ['11', '16']},{'id': '11', 'type': 'attribute', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': '_process_information'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'GetUsedMemory'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'integer', 'children': [], 'value': '0'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'display_name'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '23', 'type': 'argument_list', 'children': ['24', '27', '28']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': '_merge_task'},{'id': '27', 'type': 'string', 'children': [], 'value': "'identifier'"},{'id': '28', 'type': 'string', 'children': [], 'value': "''"},{'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': '_processing_status'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'UpdateForemanStatus'},{'id': '36', 'type': 'argument_list', 'children': ['37', '40', '43', '46', '47', '48', '51', '54', '57', '60', '63', '66', '69', '72', '75']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': '_name'},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': '_status'},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': '_pid'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'used_memory'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'display_name'},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': '_number_of_consumed_sources'},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '53', 'type': 'identifier', 'children': [], 'value': '_number_of_produced_sources'},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': '_number_of_consumed_events'},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': '_number_of_produced_events'},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': '_number_of_consumed_event_tags'},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '65', 'type': 'identifier', 'children': [], 'value': '_number_of_produced_event_tags'},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': '_number_of_consumed_warnings'},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': '_number_of_produced_warnings'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '74', 'type': 'identifier', 'children': [], 'value': '_number_of_consumed_reports'},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '77', 'type': 'identifier', 'children': [], 'value': '_number_of_produced_reports'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'call', 'children': ['80', '85']},{'id': '80', 'type': 'attribute', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': '_processing_status'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'UpdateEventsStatus'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': '_events_status'} | def _UpdateForemanProcessStatus(self):
used_memory = self._process_information.GetUsedMemory() or 0
display_name = getattr(self._merge_task, 'identifier', '')
self._processing_status.UpdateForemanStatus(
self._name, self._status, self._pid, used_memory, display_name,
self._number_of_consumed_sources, self._number_of_produced_sources,
self._number_of_consumed_events, self._number_of_produced_events,
self._number_of_consumed_event_tags,
self._number_of_produced_event_tags,
self._number_of_consumed_warnings, self._number_of_produced_warnings,
self._number_of_consumed_reports, self._number_of_produced_reports)
self._processing_status.UpdateEventsStatus(self._events_status) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'workers_status'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'return_statement', 'children': ['7']},{'id': '7', 'type': 'list_comprehension', 'children': ['8', '13']},{'id': '8', 'type': 'subscript', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': '_workers_status'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'identifier'},{'id': '13', 'type': 'for_in_clause', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'identifier'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '24']},{'id': '19', 'type': 'attribute', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': '_workers_status'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '24', 'type': 'argument_list', 'children': []} | def workers_status(self):
return [self._workers_status[identifier]
for identifier in sorted(self._workers_status.keys())] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'ProcessStorage'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '15', '26', '37', '48', '68', '81', '100', '111', '117', '125', '133', '143', '153', '163', '167', '264', '335', '341', '350', '413', '426']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'call', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': '_CheckStorageFile'},{'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': '_storage_file_path'},{'id': '15', 'type': 'expression_statement', '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': '_status_view'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'SetMode'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': '_status_view_mode'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '33']},{'id': '28', 'type': 'attribute', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': '_status_view'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'SetStorageFileInformation'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': '_storage_file_path'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'status_update_callback'},{'id': '40', 'type': '()', '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': '_status_view'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'GetAnalysisStatusUpdateCallback'},{'id': '47', 'type': 'argument_list', 'children': []},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'session'},{'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': 'engine'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'BaseEngine'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'CreateSession'},{'id': '57', 'type': 'argument_list', 'children': ['58', '63']},{'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'command_line_arguments'},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': '_command_line_arguments'},{'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'preferred_encoding'},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'preferred_encoding'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'storage_reader'},{'id': '71', 'type': 'call', 'children': ['72', '77']},{'id': '72', 'type': 'attribute', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'storage_factory'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'StorageFactory'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'CreateStorageReaderForFile'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '80', 'type': 'identifier', 'children': [], 'value': '_storage_file_path'},{'id': '81', 'type': 'if_statement', 'children': ['82', '84']},{'id': '82', 'type': 'not_operator', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'storage_reader'},{'id': '84', 'type': 'block', 'children': ['85', '99']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'string', 'children': [], 'value': "'Format of storage file: {0:s} not supported'"},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '98', 'type': 'identifier', 'children': [], 'value': '_storage_file_path'},{'id': '99', 'type': 'return_statement', 'children': []},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '104', 'type': 'identifier', 'children': [], 'value': '_number_of_analysis_reports'},{'id': '105', 'type': '()', 'children': ['106']},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'storage_reader'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'GetNumberOfAnalysisReports'},{'id': '110', 'type': 'argument_list', 'children': []},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'storage_reader'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'Close'},{'id': '116', 'type': 'argument_list', 'children': []},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'configuration'},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'configurations'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'ProcessingConfiguration'},{'id': '124', 'type': 'argument_list', 'children': []},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'configuration'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'data_location'},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '132', 'type': 'identifier', 'children': [], 'value': '_data_location'},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '140']},{'id': '135', 'type': 'attribute', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'configuration'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'profiling'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '142', 'type': 'identifier', 'children': [], 'value': '_profiling_directory'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '150']},{'id': '145', 'type': 'attribute', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'configuration'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'profiling'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'sample_rate'},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '152', 'type': 'identifier', 'children': [], 'value': '_profiling_sample_rate'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '160']},{'id': '155', 'type': 'attribute', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'configuration'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'profiling'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'profilers'},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '162', 'type': 'identifier', 'children': [], 'value': '_profilers'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'analysis_counter'},{'id': '166', 'type': 'None', 'children': []},{'id': '167', 'type': 'if_statement', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '170', 'type': 'identifier', 'children': [], 'value': '_analysis_plugins'},{'id': '171', 'type': 'block', 'children': ['172', '187', '200', '235', '243']},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'storage_writer'},{'id': '175', 'type': '()', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '182']},{'id': '177', 'type': 'attribute', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'storage_factory'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'StorageFactory'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'CreateStorageWriterForFile'},{'id': '182', 'type': 'argument_list', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '186', 'type': 'identifier', 'children': [], 'value': '_storage_file_path'},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'analysis_engine'},{'id': '190', 'type': 'call', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'psort'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'PsortMultiProcessEngine'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'keyword_argument', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'use_zeromq'},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '199', 'type': 'identifier', 'children': [], 'value': '_use_zeromq'},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'analysis_engine'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'AnalyzeEvents'},{'id': '205', 'type': 'argument_list', 'children': ['206', '209', '210', '213', '216', '217', '222', '227', '230']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '208', 'type': 'identifier', 'children': [], 'value': '_knowledge_base'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'storage_writer'},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '212', 'type': 'identifier', 'children': [], 'value': '_data_location'},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '215', 'type': 'identifier', 'children': [], 'value': '_analysis_plugins'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'configuration'},{'id': '217', 'type': 'keyword_argument', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'event_filter'},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '221', 'type': 'identifier', 'children': [], 'value': '_event_filter'},{'id': '222', 'type': 'keyword_argument', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'event_filter_expression'},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '226', 'type': 'identifier', 'children': [], 'value': '_event_filter_expression'},{'id': '227', 'type': 'keyword_argument', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'status_update_callback'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'status_update_callback'},{'id': '230', 'type': 'keyword_argument', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'worker_memory_limit'},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '234', 'type': 'identifier', 'children': [], 'value': '_worker_memory_limit'},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'analysis_counter'},{'id': '238', 'type': 'call', 'children': ['239', '242']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'Counter'},{'id': '242', 'type': 'argument_list', 'children': []},{'id': '243', 'type': 'for_statement', 'children': ['244', '247', '257']},{'id': '244', 'type': 'pattern_list', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '247', 'type': 'call', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '249', 'type': 'argument_list', 'children': ['250']},{'id': '250', 'type': 'call', 'children': ['251', '256']},{'id': '251', 'type': 'attribute', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'analysis_reports_counter'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '256', 'type': 'argument_list', 'children': []},{'id': '257', 'type': 'block', 'children': ['258']},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'assignment', 'children': ['260', '263']},{'id': '260', 'type': 'subscript', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'analysis_counter'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '264', 'type': 'if_statement', 'children': ['265', '270']},{'id': '265', 'type': 'comparison_operator', 'children': ['266', '269'], 'value': '!='},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '268', 'type': 'identifier', 'children': [], 'value': '_output_format'},{'id': '269', 'type': 'string', 'children': [], 'value': "'null'"},{'id': '270', 'type': 'block', 'children': ['271', '285', '298']},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'assignment', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'storage_reader'},{'id': '274', 'type': '()', 'children': ['275']},{'id': '275', 'type': 'call', 'children': ['276', '281']},{'id': '276', 'type': 'attribute', 'children': ['277', '280']},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'storage_factory'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'StorageFactory'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'CreateStorageReaderForFile'},{'id': '281', 'type': 'argument_list', 'children': ['282']},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '284', 'type': 'identifier', 'children': [], 'value': '_storage_file_path'},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'analysis_engine'},{'id': '288', 'type': 'call', 'children': ['289', '292']},{'id': '289', 'type': 'attribute', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'psort'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'PsortMultiProcessEngine'},{'id': '292', 'type': 'argument_list', 'children': ['293']},{'id': '293', 'type': 'keyword_argument', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'use_zeromq'},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '297', 'type': 'identifier', 'children': [], 'value': '_use_zeromq'},{'id': '298', 'type': 'expression_statement', 'children': ['299']},{'id': '299', 'type': 'call', 'children': ['300', '303']},{'id': '300', 'type': 'attribute', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'analysis_engine'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'ExportEvents'},{'id': '303', 'type': 'argument_list', 'children': ['304', '307', '308', '311', '312', '317', '322', '325', '330']},{'id': '304', 'type': 'attribute', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '306', 'type': 'identifier', 'children': [], 'value': '_knowledge_base'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'storage_reader'},{'id': '308', 'type': 'attribute', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '310', 'type': 'identifier', 'children': [], 'value': '_output_module'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'configuration'},{'id': '312', 'type': 'keyword_argument', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'deduplicate_events'},{'id': '314', 'type': 'attribute', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '316', 'type': 'identifier', 'children': [], 'value': '_deduplicate_events'},{'id': '317', 'type': 'keyword_argument', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'event_filter'},{'id': '319', 'type': 'attribute', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '321', 'type': 'identifier', 'children': [], 'value': '_event_filter'},{'id': '322', 'type': 'keyword_argument', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'status_update_callback'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'status_update_callback'},{'id': '325', 'type': 'keyword_argument', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'time_slice'},{'id': '327', 'type': 'attribute', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '329', 'type': 'identifier', 'children': [], 'value': '_time_slice'},{'id': '330', 'type': 'keyword_argument', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'use_time_slicer'},{'id': '332', 'type': 'attribute', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '334', 'type': 'identifier', 'children': [], 'value': '_use_time_slicer'},{'id': '335', 'type': 'if_statement', 'children': ['336', '339']},{'id': '336', 'type': 'attribute', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '338', 'type': 'identifier', 'children': [], 'value': '_quiet_mode'},{'id': '339', 'type': 'block', 'children': ['340']},{'id': '340', 'type': 'return_statement', 'children': []},{'id': '341', 'type': 'expression_statement', 'children': ['342']},{'id': '342', 'type': 'call', 'children': ['343', '348']},{'id': '343', 'type': 'attribute', 'children': ['344', '347']},{'id': '344', 'type': 'attribute', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '346', 'type': 'identifier', 'children': [], 'value': '_output_writer'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'Write'},{'id': '348', 'type': 'argument_list', 'children': ['349']},{'id': '349', 'type': 'string', 'children': [], 'value': "'Processing completed.\\n'"},{'id': '350', 'type': 'if_statement', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'analysis_counter'},{'id': '352', 'type': 'block', 'children': ['353', '369', '393', '404']},{'id': '353', 'type': 'expression_statement', 'children': ['354']},{'id': '354', 'type': 'assignment', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'table_view'},{'id': '356', 'type': 'call', 'children': ['357', '362']},{'id': '357', 'type': 'attribute', 'children': ['358', '361']},{'id': '358', 'type': 'attribute', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'views'},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'ViewsFactory'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'GetTableView'},{'id': '362', 'type': 'argument_list', 'children': ['363', '366']},{'id': '363', 'type': 'attribute', 'children': ['364', '365']},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '365', 'type': 'identifier', 'children': [], 'value': '_views_format_type'},{'id': '366', 'type': 'keyword_argument', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '368', 'type': 'string', 'children': [], 'value': "'Analysis reports generated'"},{'id': '369', 'type': 'for_statement', 'children': ['370', '373', '378']},{'id': '370', 'type': 'pattern_list', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '373', 'type': 'call', 'children': ['374', '377']},{'id': '374', 'type': 'attribute', 'children': ['375', '376']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'analysis_counter'},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'most_common'},{'id': '377', 'type': 'argument_list', 'children': []},{'id': '378', 'type': 'block', 'children': ['379']},{'id': '379', 'type': 'if_statement', 'children': ['380', '383']},{'id': '380', 'type': 'comparison_operator', 'children': ['381', '382'], 'value': '!='},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '382', 'type': 'string', 'children': [], 'value': "'total'"},{'id': '383', 'type': 'block', 'children': ['384']},{'id': '384', 'type': 'expression_statement', 'children': ['385']},{'id': '385', 'type': 'call', 'children': ['386', '389']},{'id': '386', 'type': 'attribute', 'children': ['387', '388']},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'table_view'},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'AddRow'},{'id': '389', 'type': 'argument_list', 'children': ['390']},{'id': '390', 'type': 'list', 'children': ['391', '392'], 'value': '[element, count]'},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '393', 'type': 'expression_statement', 'children': ['394']},{'id': '394', 'type': 'call', 'children': ['395', '398']},{'id': '395', 'type': 'attribute', 'children': ['396', '397']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'table_view'},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'AddRow'},{'id': '398', 'type': 'argument_list', 'children': ['399']},{'id': '399', 'type': 'list', 'children': ['400', '401'], 'value': "['Total', analysis_counter['total']]"},{'id': '400', 'type': 'string', 'children': [], 'value': "'Total'"},{'id': '401', 'type': 'subscript', 'children': ['402', '403']},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'analysis_counter'},{'id': '403', 'type': 'string', 'children': [], 'value': "'total'"},{'id': '404', 'type': 'expression_statement', 'children': ['405']},{'id': '405', 'type': 'call', 'children': ['406', '409']},{'id': '406', 'type': 'attribute', 'children': ['407', '408']},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'table_view'},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'Write'},{'id': '409', 'type': 'argument_list', 'children': ['410']},{'id': '410', 'type': 'attribute', 'children': ['411', '412']},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '412', 'type': 'identifier', 'children': [], 'value': '_output_writer'},{'id': '413', 'type': 'expression_statement', 'children': ['414']},{'id': '414', 'type': 'assignment', 'children': ['415', '416']},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'storage_reader'},{'id': '416', 'type': 'call', 'children': ['417', '422']},{'id': '417', 'type': 'attribute', 'children': ['418', '421']},{'id': '418', 'type': 'attribute', 'children': ['419', '420']},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'storage_factory'},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'StorageFactory'},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'CreateStorageReaderForFile'},{'id': '422', 'type': 'argument_list', 'children': ['423']},{'id': '423', 'type': 'attribute', 'children': ['424', '425']},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '425', 'type': 'identifier', 'children': [], 'value': '_storage_file_path'},{'id': '426', 'type': 'expression_statement', 'children': ['427']},{'id': '427', 'type': 'call', 'children': ['428', '431']},{'id': '428', 'type': 'attribute', 'children': ['429', '430']},{'id': '429', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '430', 'type': 'identifier', 'children': [], 'value': '_PrintAnalysisReportsDetails'},{'id': '431', 'type': 'argument_list', 'children': ['432']},{'id': '432', 'type': 'identifier', 'children': [], 'value': 'storage_reader'} | def ProcessStorage(self):
self._CheckStorageFile(self._storage_file_path)
self._status_view.SetMode(self._status_view_mode)
self._status_view.SetStorageFileInformation(self._storage_file_path)
status_update_callback = (
self._status_view.GetAnalysisStatusUpdateCallback())
session = engine.BaseEngine.CreateSession(
command_line_arguments=self._command_line_arguments,
preferred_encoding=self.preferred_encoding)
storage_reader = storage_factory.StorageFactory.CreateStorageReaderForFile(
self._storage_file_path)
if not storage_reader:
logger.error('Format of storage file: {0:s} not supported'.format(
self._storage_file_path))
return
self._number_of_analysis_reports = (
storage_reader.GetNumberOfAnalysisReports())
storage_reader.Close()
configuration = configurations.ProcessingConfiguration()
configuration.data_location = self._data_location
configuration.profiling.directory = self._profiling_directory
configuration.profiling.sample_rate = self._profiling_sample_rate
configuration.profiling.profilers = self._profilers
analysis_counter = None
if self._analysis_plugins:
storage_writer = (
storage_factory.StorageFactory.CreateStorageWriterForFile(
session, self._storage_file_path))
analysis_engine = psort.PsortMultiProcessEngine(
use_zeromq=self._use_zeromq)
analysis_engine.AnalyzeEvents(
self._knowledge_base, storage_writer, self._data_location,
self._analysis_plugins, configuration,
event_filter=self._event_filter,
event_filter_expression=self._event_filter_expression,
status_update_callback=status_update_callback,
worker_memory_limit=self._worker_memory_limit)
analysis_counter = collections.Counter()
for item, value in iter(session.analysis_reports_counter.items()):
analysis_counter[item] = value
if self._output_format != 'null':
storage_reader = (
storage_factory.StorageFactory.CreateStorageReaderForFile(
self._storage_file_path))
analysis_engine = psort.PsortMultiProcessEngine(
use_zeromq=self._use_zeromq)
analysis_engine.ExportEvents(
self._knowledge_base, storage_reader, self._output_module,
configuration, deduplicate_events=self._deduplicate_events,
event_filter=self._event_filter,
status_update_callback=status_update_callback,
time_slice=self._time_slice, use_time_slicer=self._use_time_slicer)
if self._quiet_mode:
return
self._output_writer.Write('Processing completed.\n')
if analysis_counter:
table_view = views.ViewsFactory.GetTableView(
self._views_format_type, title='Analysis reports generated')
for element, count in analysis_counter.most_common():
if element != 'total':
table_view.AddRow([element, count])
table_view.AddRow(['Total', analysis_counter['total']])
table_view.Write(self._output_writer)
storage_reader = storage_factory.StorageFactory.CreateStorageReaderForFile(
self._storage_file_path)
self._PrintAnalysisReportsDetails(storage_reader) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_state'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'best_hyp_indices'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'attribute', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'mx'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'nd'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'NDArray'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'states'},{'id': '19', 'type': 'list_comprehension', 'children': ['20', '29']},{'id': '20', 'type': 'call', 'children': ['21', '26']},{'id': '21', 'type': 'attribute', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'mx'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'nd'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'take'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'ds'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'best_hyp_indices'},{'id': '29', 'type': 'for_in_clause', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'ds'},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'states'} | def sort_state(self, best_hyp_indices: mx.nd.NDArray):
self.states = [mx.nd.take(ds, best_hyp_indices) for ds in self.states] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19', '27']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'rerank'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'hypotheses'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'generic_type', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'Dict'},{'id': '10', 'type': 'type_parameter', 'children': ['11', '13']},{'id': '11', 'type': 'type', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '13', 'type': 'type', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'Any'},{'id': '15', 'type': 'typed_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'reference'},{'id': '17', 'type': 'type', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '19', 'type': 'type', 'children': ['20']},{'id': '20', 'type': 'generic_type', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'Dict'},{'id': '22', 'type': 'type_parameter', 'children': ['23', '25']},{'id': '23', 'type': 'type', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '25', 'type': 'type', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'Any'},{'id': '27', 'type': 'block', 'children': ['28', '44', '65', '75', '92']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '31', 'type': 'list_comprehension', 'children': ['32', '39']},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'scoring_function'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'hypothesis'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'reference'},{'id': '39', 'type': 'for_in_clause', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'hypothesis'},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'hypotheses'},{'id': '43', 'type': 'string', 'children': [], 'value': "'translations'"},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'ranking'},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'subscript', 'children': ['51', '60']},{'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': 'argsort'},{'id': '55', 'type': 'argument_list', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '59', 'type': 'string', 'children': [], 'value': "'mergesort'"},{'id': '60', 'type': 'slice', 'children': ['61', '62', '63']},{'id': '61', 'type': 'colon', 'children': []},{'id': '62', 'type': 'colon', 'children': []},{'id': '63', 'type': 'unary_operator', 'children': ['64'], 'value': '-'},{'id': '64', 'type': 'integer', 'children': [], 'value': '1'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'reranked_hypotheses'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': '_sort_by_ranking'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'hypotheses'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'ranking'},{'id': '75', 'type': 'if_statement', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'return_score'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '85']},{'id': '82', 'type': 'subscript', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'reranked_hypotheses'},{'id': '84', 'type': 'string', 'children': [], 'value': "'scores'"},{'id': '85', 'type': 'list_comprehension', 'children': ['86', '89']},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '89', 'type': 'for_in_clause', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'ranking'},{'id': '92', 'type': 'return_statement', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'reranked_hypotheses'} | def rerank(self, hypotheses: Dict[str, Any], reference: str) -> Dict[str, Any]:
scores = [self.scoring_function(hypothesis, reference) for hypothesis in hypotheses['translations']]
ranking = list(np.argsort(scores, kind='mergesort')[::-1])
reranked_hypotheses = self._sort_by_ranking(hypotheses, ranking)
if self.return_score:
reranked_hypotheses['scores'] = [scores[i] for i in ranking]
return reranked_hypotheses |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'load'},{'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': 'path'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '9', 'type': 'typed_default_parameter', 'children': ['10', '11', '17']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '11', 'type': 'type', 'children': ['12']},{'id': '12', 'type': 'generic_type', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'Optional'},{'id': '14', 'type': 'type_parameter', 'children': ['15']},{'id': '15', 'type': 'type', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '27', '48', '56', '91', '114', '142', '152']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'load_time_start'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'with_statement', 'children': ['28', '38']},{'id': '28', 'type': 'with_clause', 'children': ['29']},{'id': '29', 'type': 'with_item', 'children': ['30']},{'id': '30', 'type': 'as_pattern', 'children': ['31', '36']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '35', 'type': 'string', 'children': [], 'value': "'rb'"},{'id': '36', 'type': 'as_pattern_target', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'inp'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': '_lex'},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'load'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'inp'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'loaded_k'},{'id': '51', 'type': 'subscript', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': '_lex'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '55', 'type': 'integer', 'children': [], 'value': '1'},{'id': '56', 'type': 'if_statement', 'children': ['57', '60', '85']},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': 'is'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'k'},{'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': 'top_k'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '66', 'type': 'argument_list', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'loaded_k'},{'id': '69', 'type': 'if_statement', 'children': ['70', '73']},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': '>'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'loaded_k'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '79', 'type': 'argument_list', 'children': ['80', '83', '84']},{'id': '80', 'type': 'concatenated_string', 'children': ['81', '82']},{'id': '81', 'type': 'string', 'children': [], 'value': '"Can not load top-%d translations from lexicon that "'},{'id': '82', 'type': 'string', 'children': [], 'value': '"contains at most %d entries per source."'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'loaded_k'},{'id': '85', 'type': 'else_clause', 'children': ['86']},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'top_k'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'loaded_k'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'lex'},{'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': 'zeros'},{'id': '100', 'type': 'argument_list', 'children': ['101', '109']},{'id': '101', 'type': 'tuple', 'children': ['102', '108']},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'vocab_source'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'top_k'},{'id': '109', 'type': 'keyword_argument', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': '_lex'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '114', 'type': 'for_statement', 'children': ['115', '118', '122']},{'id': '115', 'type': 'pattern_list', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'src_id'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'trg_ids'},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': '_lex'},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '132']},{'id': '125', 'type': 'subscript', 'children': ['126', '129', '130']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'lex'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'src_id'},{'id': '130', 'type': 'slice', 'children': ['131']},{'id': '131', 'type': 'colon', 'children': []},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'trg_ids'},{'id': '139', 'type': 'slice', 'children': ['140', '141']},{'id': '140', 'type': 'colon', 'children': []},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'top_k'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'load_time'},{'id': '145', 'type': 'binary_operator', 'children': ['146', '151'], 'value': '-'},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '150', 'type': 'argument_list', 'children': []},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'load_time_start'},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '157', 'type': 'argument_list', 'children': ['158', '159', '160', '161']},{'id': '158', 'type': 'string', 'children': [], 'value': '"Loaded top-%d lexicon from \\"%s\\" in %.4fs."'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'top_k'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'load_time'} | def load(self, path: str, k: Optional[int] = None):
load_time_start = time.time()
with open(path, 'rb') as inp:
_lex = np.load(inp)
loaded_k = _lex.shape[1]
if k is not None:
top_k = min(k, loaded_k)
if k > loaded_k:
logger.warning("Can not load top-%d translations from lexicon that "
"contains at most %d entries per source.", k, loaded_k)
else:
top_k = loaded_k
self.lex = np.zeros((len(self.vocab_source), top_k), dtype=_lex.dtype)
for src_id, trg_ids in enumerate(_lex):
self.lex[src_id, :] = np.sort(trg_ids[:top_k])
load_time = time.time() - load_time_start
logger.info("Loaded top-%d lexicon from \"%s\" in %.4fs.", top_k, path, load_time) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_trg_ids'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'src_ids'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'ndarray'},{'id': '11', 'type': 'type', 'children': ['12']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ndarray'},{'id': '15', 'type': 'block', 'children': ['16', '29', '57']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'unique_src_ids'},{'id': '19', 'type': 'call', 'children': ['20', '27']},{'id': '20', 'type': 'attribute', 'children': ['21', '26']},{'id': '21', 'type': 'attribute', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'lib'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'arraysetops'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'src_ids'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'trg_ids'},{'id': '32', 'type': 'call', 'children': ['33', '40']},{'id': '33', 'type': 'attribute', 'children': ['34', '39']},{'id': '34', 'type': 'attribute', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'lib'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'arraysetops'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'union1d'},{'id': '40', 'type': 'argument_list', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'always_allow'},{'id': '44', 'type': 'call', 'children': ['45', '54']},{'id': '45', 'type': 'attribute', 'children': ['46', '53']},{'id': '46', 'type': 'subscript', 'children': ['47', '50', '51']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'lex'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'unique_src_ids'},{'id': '51', 'type': 'slice', 'children': ['52']},{'id': '52', 'type': 'colon', 'children': []},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'reshape'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'unary_operator', 'children': ['56'], 'value': '-'},{'id': '56', 'type': 'integer', 'children': [], 'value': '1'},{'id': '57', 'type': 'return_statement', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'trg_ids'} | def get_trg_ids(self, src_ids: np.ndarray) -> np.ndarray:
unique_src_ids = np.lib.arraysetops.unique(src_ids)
trg_ids = np.lib.arraysetops.union1d(self.always_allow, self.lex[unique_src_ids, :].reshape(-1))
return trg_ids |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'choice'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '6', 'type': 'block', 'children': ['7', '24', '41']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'tree_id'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '12', 'type': 'argument_list', 'children': ['13', '14', '23']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '14', 'type': 'attribute', 'children': ['15', '22']},{'id': '15', 'type': 'attribute', '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': 'queryset'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '21', 'type': 'identifier', 'children': [], 'value': '_mptt_meta'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'tree_id_attr'},{'id': '23', 'type': 'integer', 'children': [], 'value': '0'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'left'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31', '40']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '31', 'type': 'attribute', 'children': ['32', '39']},{'id': '32', 'type': 'attribute', 'children': ['33', '38']},{'id': '33', 'type': 'attribute', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'queryset'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '38', 'type': 'identifier', 'children': [], 'value': '_mptt_meta'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'left_attr'},{'id': '40', 'type': 'integer', 'children': [], 'value': '0'},{'id': '41', 'type': 'return_statement', 'children': ['42']},{'id': '42', 'type': 'binary_operator', 'children': ['43', '53'], 'value': '+'},{'id': '43', 'type': 'call', 'children': ['44', '51']},{'id': '44', 'type': 'attribute', 'children': ['45', '50']},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'MPTTModelChoiceIterator'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'choice'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '53', 'type': 'tuple', 'children': ['54']},{'id': '54', 'type': 'tuple', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'tree_id'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'left'} | def choice(self, obj):
tree_id = getattr(obj, self.queryset.model._mptt_meta.tree_id_attr, 0)
left = getattr(obj, self.queryset.model._mptt_meta.left_attr, 0)
return super(MPTTModelChoiceIterator,
self).choice(obj) + ((tree_id, left),) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_best_dataset_key'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '6', 'type': 'block', 'children': ['7', '61', '110', '165', '212', '259']},{'id': '7', 'type': 'if_statement', 'children': ['8', '15']},{'id': '8', 'type': 'boolean_operator', 'children': ['9', '14'], 'value': 'and'},{'id': '9', 'type': 'comparison_operator', 'children': ['10', '13'], 'value': 'is'},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'wavelength'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '15', 'type': 'block', 'children': ['16', '41']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'nearest_wl'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'list_comprehension', 'children': ['23', '32', '35']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': '_wl_dist'},{'id': '25', 'type': 'argument_list', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'wavelength'},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'wavelength'},{'id': '32', 'type': 'for_in_clause', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '35', 'type': 'if_clause', 'children': ['36']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '40'], 'value': 'is'},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'wavelength'},{'id': '40', 'type': 'None', 'children': []},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '44', 'type': 'list_comprehension', 'children': ['45', '46', '49']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '46', 'type': 'for_in_clause', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '49', 'type': 'if_clause', 'children': ['50']},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '60'], 'value': '=='},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': '_wl_dist'},{'id': '53', 'type': 'argument_list', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'wavelength'},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'wavelength'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'nearest_wl'},{'id': '61', 'type': 'if_statement', 'children': ['62', '69']},{'id': '62', 'type': 'boolean_operator', 'children': ['63', '68'], 'value': 'and'},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '67'], 'value': 'is'},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'modifiers'},{'id': '67', 'type': 'None', 'children': []},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '69', 'type': 'block', 'children': ['70', '89']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'num_modifiers'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '75', 'type': 'generator_expression', 'children': ['76', '86']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'boolean_operator', 'children': ['80', '83'], 'value': 'or'},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'modifiers'},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '85', 'type': 'argument_list', 'children': []},{'id': '86', 'type': 'for_in_clause', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '92', 'type': 'list_comprehension', 'children': ['93', '94', '97']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '94', 'type': 'for_in_clause', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '97', 'type': 'if_clause', 'children': ['98']},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '109'], 'value': '=='},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'boolean_operator', 'children': ['103', '106'], 'value': 'or'},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'modifiers'},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '108', 'type': 'argument_list', 'children': []},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'num_modifiers'},{'id': '110', 'type': 'if_statement', 'children': ['111', '118']},{'id': '111', 'type': 'boolean_operator', 'children': ['112', '117'], 'value': 'and'},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '116'], 'value': 'is'},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'calibration'},{'id': '116', 'type': 'None', 'children': []},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '118', 'type': 'block', 'children': ['119', '133']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'best_cal'},{'id': '122', 'type': 'list_comprehension', 'children': ['123', '126', '129']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'calibration'},{'id': '126', 'type': 'for_in_clause', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '129', 'type': 'if_clause', 'children': ['130']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'calibration'},{'id': '133', 'type': 'if_statement', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'best_cal'},{'id': '135', 'type': 'block', 'children': ['136', '151']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'best_cal'},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '141', 'type': 'argument_list', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'best_cal'},{'id': '143', 'type': 'keyword_argument', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '145', 'type': 'lambda', 'children': ['146', '148']},{'id': '146', 'type': 'lambda_parameters', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '148', 'type': 'subscript', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'CALIBRATION_ORDER'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '154', 'type': 'list_comprehension', 'children': ['155', '156', '159']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '156', 'type': 'for_in_clause', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '159', 'type': 'if_clause', 'children': ['160']},{'id': '160', 'type': 'comparison_operator', 'children': ['161', '164'], 'value': '=='},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'calibration'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'best_cal'},{'id': '165', 'type': 'if_statement', 'children': ['166', '173']},{'id': '166', 'type': 'boolean_operator', 'children': ['167', '172'], 'value': 'and'},{'id': '167', 'type': 'comparison_operator', 'children': ['168', '171'], 'value': 'is'},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'resolution'},{'id': '171', 'type': 'None', 'children': []},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'choices'},{'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': 'low_res'},{'id': '177', 'type': 'list_comprehension', 'children': ['178', '181', '184']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'resolution'},{'id': '181', 'type': 'for_in_clause', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '184', 'type': 'if_clause', 'children': ['185']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'resolution'},{'id': '188', 'type': 'if_statement', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'low_res'},{'id': '190', 'type': 'block', 'children': ['191', '198']},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'low_res'},{'id': '194', 'type': 'call', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'low_res'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '201', 'type': 'list_comprehension', 'children': ['202', '203', '206']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '203', 'type': 'for_in_clause', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '206', 'type': 'if_clause', 'children': ['207']},{'id': '207', 'type': 'comparison_operator', 'children': ['208', '211'], 'value': '=='},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'resolution'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'low_res'},{'id': '212', 'type': 'if_statement', 'children': ['213', '220']},{'id': '213', 'type': 'boolean_operator', 'children': ['214', '219'], 'value': 'and'},{'id': '214', 'type': 'comparison_operator', 'children': ['215', '218'], 'value': 'is'},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '218', 'type': 'None', 'children': []},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '220', 'type': 'block', 'children': ['221', '235']},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'low_level'},{'id': '224', 'type': 'list_comprehension', 'children': ['225', '228', '231']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '228', 'type': 'for_in_clause', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '231', 'type': 'if_clause', 'children': ['232']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '235', 'type': 'if_statement', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'low_level'},{'id': '237', 'type': 'block', 'children': ['238', '245']},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'low_level'},{'id': '241', 'type': 'call', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '243', 'type': 'argument_list', 'children': ['244']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'low_level'},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'assignment', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '248', 'type': 'list_comprehension', 'children': ['249', '250', '253']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '250', 'type': 'for_in_clause', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '253', 'type': 'if_clause', 'children': ['254']},{'id': '254', 'type': 'comparison_operator', 'children': ['255', '258'], 'value': '=='},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'low_level'},{'id': '259', 'type': 'return_statement', 'children': ['260']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'choices'} | def get_best_dataset_key(key, choices):
if key.wavelength is not None and choices:
nearest_wl = min([_wl_dist(key.wavelength, x.wavelength)
for x in choices if x.wavelength is not None])
choices = [c for c in choices
if _wl_dist(key.wavelength, c.wavelength) == nearest_wl]
if key.modifiers is None and choices:
num_modifiers = min(len(x.modifiers or tuple()) for x in choices)
choices = [c for c in choices if len(
c.modifiers or tuple()) == num_modifiers]
if key.calibration is None and choices:
best_cal = [x.calibration for x in choices if x.calibration]
if best_cal:
best_cal = min(best_cal, key=lambda x: CALIBRATION_ORDER[x])
choices = [c for c in choices if c.calibration == best_cal]
if key.resolution is None and choices:
low_res = [x.resolution for x in choices if x.resolution]
if low_res:
low_res = min(low_res)
choices = [c for c in choices if c.resolution == low_res]
if key.level is None and choices:
low_level = [x.level for x in choices if x.level]
if low_level:
low_level = max(low_level)
choices = [c for c in choices if c.level == low_level]
return choices |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '27']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_key'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key_container'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'num_results'},{'id': '8', 'type': 'integer', 'children': [], 'value': '1'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'best'},{'id': '11', 'type': 'True', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'resolution'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'calibration'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'polarization'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'modifiers'},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'block', 'children': ['28', '98', '106', '146', '186', '226', '266', '291', '302']},{'id': '28', 'type': 'if_statement', 'children': ['29', '36', '49', '72']},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'numbers'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'Number'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'DatasetID'},{'id': '42', 'type': 'argument_list', 'children': ['43', '46']},{'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'wavelength'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'modifiers'},{'id': '48', 'type': 'None', 'children': []},{'id': '49', 'type': 'elif_clause', 'children': ['50', '59']},{'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': 'key'},{'id': '54', 'type': 'tuple', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'text_type'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'DatasetID'},{'id': '65', 'type': 'argument_list', 'children': ['66', '69']},{'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'modifiers'},{'id': '71', 'type': 'None', 'children': []},{'id': '72', 'type': 'elif_clause', 'children': ['73', '79']},{'id': '73', 'type': 'not_operator', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'DatasetID'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'raise_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '90']},{'id': '85', 'type': 'attribute', 'children': ['86', '89']},{'id': '86', 'type': 'concatenated_string', 'children': ['87', '88']},{'id': '87', 'type': 'string', 'children': [], 'value': '"Expected \'DatasetID\', str, or number dict key, "'},{'id': '88', 'type': 'string', 'children': [], 'value': '"not {}"'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'filter_keys_by_dataset_id'},{'id': '103', 'type': 'argument_list', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'key_container'},{'id': '106', 'type': 'if_statement', 'children': ['107', '110']},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '109'], 'value': 'is'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'resolution'},{'id': '109', 'type': 'None', 'children': []},{'id': '110', 'type': 'block', 'children': ['111', '126']},{'id': '111', 'type': 'if_statement', 'children': ['112', '120']},{'id': '112', 'type': 'not_operator', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '115', 'type': 'argument_list', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'resolution'},{'id': '117', 'type': 'tuple', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'resolution'},{'id': '124', 'type': 'tuple', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'resolution'},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '129', 'type': 'list_comprehension', 'children': ['130', '131', '134']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '131', 'type': 'for_in_clause', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '134', 'type': 'if_clause', 'children': ['135']},{'id': '135', 'type': 'boolean_operator', 'children': ['136', '141'], 'value': 'and'},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '140'], 'value': 'is'},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'resolution'},{'id': '140', 'type': 'None', 'children': []},{'id': '141', 'type': 'comparison_operator', 'children': ['142', '145'], 'value': 'in'},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'resolution'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'resolution'},{'id': '146', 'type': 'if_statement', 'children': ['147', '150']},{'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': 'is'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'polarization'},{'id': '149', 'type': 'None', 'children': []},{'id': '150', 'type': 'block', 'children': ['151', '166']},{'id': '151', 'type': 'if_statement', 'children': ['152', '160']},{'id': '152', 'type': 'not_operator', 'children': ['153']},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '155', 'type': 'argument_list', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'polarization'},{'id': '157', 'type': 'tuple', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '160', 'type': 'block', 'children': ['161']},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'polarization'},{'id': '164', 'type': 'tuple', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'polarization'},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '169', 'type': 'list_comprehension', 'children': ['170', '171', '174']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '171', 'type': 'for_in_clause', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '174', 'type': 'if_clause', 'children': ['175']},{'id': '175', 'type': 'boolean_operator', 'children': ['176', '181'], 'value': 'and'},{'id': '176', 'type': 'comparison_operator', 'children': ['177', '180'], 'value': 'is'},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'polarization'},{'id': '180', 'type': 'None', 'children': []},{'id': '181', 'type': 'comparison_operator', 'children': ['182', '185'], 'value': 'in'},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'polarization'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'polarization'},{'id': '186', 'type': 'if_statement', 'children': ['187', '190']},{'id': '187', 'type': 'comparison_operator', 'children': ['188', '189'], 'value': 'is'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'calibration'},{'id': '189', 'type': 'None', 'children': []},{'id': '190', 'type': 'block', 'children': ['191', '206']},{'id': '191', 'type': 'if_statement', 'children': ['192', '200']},{'id': '192', 'type': 'not_operator', 'children': ['193']},{'id': '193', 'type': 'call', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '195', 'type': 'argument_list', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'calibration'},{'id': '197', 'type': 'tuple', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'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': 'calibration'},{'id': '204', 'type': 'tuple', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'calibration'},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '209', 'type': 'list_comprehension', 'children': ['210', '211', '214']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '211', 'type': 'for_in_clause', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '214', 'type': 'if_clause', 'children': ['215']},{'id': '215', 'type': 'boolean_operator', 'children': ['216', '221'], 'value': 'and'},{'id': '216', 'type': 'comparison_operator', 'children': ['217', '220'], 'value': 'is'},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'calibration'},{'id': '220', 'type': 'None', 'children': []},{'id': '221', 'type': 'comparison_operator', 'children': ['222', '225'], 'value': 'in'},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'calibration'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'calibration'},{'id': '226', 'type': 'if_statement', 'children': ['227', '230']},{'id': '227', 'type': 'comparison_operator', 'children': ['228', '229'], 'value': 'is'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '229', 'type': 'None', 'children': []},{'id': '230', 'type': 'block', 'children': ['231', '246']},{'id': '231', 'type': 'if_statement', 'children': ['232', '240']},{'id': '232', 'type': 'not_operator', 'children': ['233']},{'id': '233', 'type': 'call', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '235', 'type': 'argument_list', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '237', 'type': 'tuple', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '240', 'type': 'block', 'children': ['241']},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'assignment', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '244', 'type': 'tuple', 'children': ['245']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '249', 'type': 'list_comprehension', 'children': ['250', '251', '254']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '251', 'type': 'for_in_clause', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '254', 'type': 'if_clause', 'children': ['255']},{'id': '255', 'type': 'boolean_operator', 'children': ['256', '261'], 'value': 'and'},{'id': '256', 'type': 'comparison_operator', 'children': ['257', '260'], 'value': 'is'},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '260', 'type': 'None', 'children': []},{'id': '261', 'type': 'comparison_operator', 'children': ['262', '265'], 'value': 'in'},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '266', 'type': 'if_statement', 'children': ['267', '270']},{'id': '267', 'type': 'comparison_operator', 'children': ['268', '269'], 'value': 'is'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'modifiers'},{'id': '269', 'type': 'None', 'children': []},{'id': '270', 'type': 'block', 'children': ['271']},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'assignment', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '274', 'type': 'list_comprehension', 'children': ['275', '276', '279']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '276', 'type': 'for_in_clause', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '279', 'type': 'if_clause', 'children': ['280']},{'id': '280', 'type': 'boolean_operator', 'children': ['281', '286'], 'value': 'and'},{'id': '281', 'type': 'comparison_operator', 'children': ['282', '285'], 'value': 'is'},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'modifiers'},{'id': '285', 'type': 'None', 'children': []},{'id': '286', 'type': 'comparison_operator', 'children': ['287', '290'], 'value': '=='},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'modifiers'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'modifiers'},{'id': '291', 'type': 'if_statement', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'best'},{'id': '293', 'type': 'block', 'children': ['294']},{'id': '294', 'type': 'expression_statement', 'children': ['295']},{'id': '295', 'type': 'assignment', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '297', 'type': 'call', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'get_best_dataset_key'},{'id': '299', 'type': 'argument_list', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '302', 'type': 'if_statement', 'children': ['303', '309', '323', '348', '357', '364']},{'id': '303', 'type': 'boolean_operator', 'children': ['304', '307'], 'value': 'and'},{'id': '304', 'type': 'comparison_operator', 'children': ['305', '306'], 'value': '=='},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'num_results'},{'id': '306', 'type': 'integer', 'children': [], 'value': '1'},{'id': '307', 'type': 'not_operator', 'children': ['308']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '309', 'type': 'block', 'children': ['310']},{'id': '310', 'type': 'raise_statement', 'children': ['311']},{'id': '311', 'type': 'call', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '313', 'type': 'argument_list', 'children': ['314']},{'id': '314', 'type': 'call', 'children': ['315', '318']},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'string', 'children': [], 'value': '"No dataset matching \'{}\' found"'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '318', 'type': 'argument_list', 'children': ['319']},{'id': '319', 'type': 'call', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '321', 'type': 'argument_list', 'children': ['322']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '323', 'type': 'elif_clause', 'children': ['324', '334']},{'id': '324', 'type': 'boolean_operator', 'children': ['325', '328'], 'value': 'and'},{'id': '325', 'type': 'comparison_operator', 'children': ['326', '327'], 'value': '=='},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'num_results'},{'id': '327', 'type': 'integer', 'children': [], 'value': '1'},{'id': '328', 'type': 'comparison_operator', 'children': ['329', '333'], 'value': '!='},{'id': '329', 'type': 'call', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '331', 'type': 'argument_list', 'children': ['332']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '333', 'type': 'integer', 'children': [], 'value': '1'},{'id': '334', 'type': 'block', 'children': ['335']},{'id': '335', 'type': 'raise_statement', 'children': ['336']},{'id': '336', 'type': 'call', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'TooManyResults'},{'id': '338', 'type': 'argument_list', 'children': ['339']},{'id': '339', 'type': 'call', 'children': ['340', '343']},{'id': '340', 'type': 'attribute', 'children': ['341', '342']},{'id': '341', 'type': 'string', 'children': [], 'value': '"No unique dataset matching {}"'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '343', 'type': 'argument_list', 'children': ['344']},{'id': '344', 'type': 'call', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '346', 'type': 'argument_list', 'children': ['347']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '348', 'type': 'elif_clause', 'children': ['349', '352']},{'id': '349', 'type': 'comparison_operator', 'children': ['350', '351'], 'value': '=='},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'num_results'},{'id': '351', 'type': 'integer', 'children': [], 'value': '1'},{'id': '352', 'type': 'block', 'children': ['353']},{'id': '353', 'type': 'return_statement', 'children': ['354']},{'id': '354', 'type': 'subscript', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '356', 'type': 'integer', 'children': [], 'value': '0'},{'id': '357', 'type': 'elif_clause', 'children': ['358', '361']},{'id': '358', 'type': 'comparison_operator', 'children': ['359', '360'], 'value': '=='},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'num_results'},{'id': '360', 'type': 'integer', 'children': [], 'value': '0'},{'id': '361', 'type': 'block', 'children': ['362']},{'id': '362', 'type': 'return_statement', 'children': ['363']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '364', 'type': 'else_clause', 'children': ['365']},{'id': '365', 'type': 'block', 'children': ['366']},{'id': '366', 'type': 'return_statement', 'children': ['367']},{'id': '367', 'type': 'subscript', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '369', 'type': 'slice', 'children': ['370', '371']},{'id': '370', 'type': 'colon', 'children': []},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'num_results'} | def get_key(key, key_container, num_results=1, best=True,
resolution=None, calibration=None, polarization=None,
level=None, modifiers=None):
if isinstance(key, numbers.Number):
key = DatasetID(wavelength=key, modifiers=None)
elif isinstance(key, (str, six.text_type)):
key = DatasetID(name=key, modifiers=None)
elif not isinstance(key, DatasetID):
raise ValueError("Expected 'DatasetID', str, or number dict key, "
"not {}".format(str(type(key))))
res = filter_keys_by_dataset_id(key, key_container)
if resolution is not None:
if not isinstance(resolution, (list, tuple)):
resolution = (resolution, )
res = [k for k in res
if k.resolution is not None and k.resolution in resolution]
if polarization is not None:
if not isinstance(polarization, (list, tuple)):
polarization = (polarization, )
res = [k for k in res
if k.polarization is not None and k.polarization in
polarization]
if calibration is not None:
if not isinstance(calibration, (list, tuple)):
calibration = (calibration, )
res = [k for k in res
if k.calibration is not None and k.calibration in calibration]
if level is not None:
if not isinstance(level, (list, tuple)):
level = (level, )
res = [k for k in res
if k.level is not None and k.level in level]
if modifiers is not None:
res = [k for k in res
if k.modifiers is not None and k.modifiers == modifiers]
if best:
res = get_best_dataset_key(key, res)
if num_results == 1 and not res:
raise KeyError("No dataset matching '{}' found".format(str(key)))
elif num_results == 1 and len(res) != 1:
raise TooManyResults("No unique dataset matching {}".format(str(key)))
elif num_results == 1:
return res[0]
elif num_results == 0:
return res
else:
return res[:num_results] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'group_files'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'files_to_sort'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'reader'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'time_threshold'},{'id': '10', 'type': 'integer', 'children': [], 'value': '10'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'group_keys'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'ppp_config_dir'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'reader_kwargs'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'block', 'children': ['21', '46', '52', '65', '71', '115', '133', '137', '183', '187', '196', '200', '318', '325']},{'id': '21', 'type': 'if_statement', 'children': ['22', '25', '31']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'is'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'reader'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'raise_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'string', 'children': [], 'value': '"\'reader\' keyword argument is required."'},{'id': '31', 'type': 'elif_clause', 'children': ['32', '40']},{'id': '32', 'type': 'not_operator', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'reader'},{'id': '37', 'type': 'tuple', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'reader'},{'id': '44', 'type': 'list', 'children': ['45'], 'value': '[reader]'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'reader'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'reader'},{'id': '49', 'type': 'subscript', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'reader'},{'id': '51', 'type': 'integer', 'children': [], 'value': '0'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'reader_configs'},{'id': '55', 'type': 'subscript', 'children': ['56', '64']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'configs_for_reader'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'reader'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'ppp_config_dir'},{'id': '64', 'type': 'integer', 'children': [], 'value': '0'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'reader_kwargs'},{'id': '68', 'type': 'boolean_operator', 'children': ['69', '70'], 'value': 'or'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'reader_kwargs'},{'id': '70', 'type': 'dictionary', 'children': []},{'id': '71', 'type': 'try_statement', 'children': ['72', '82']},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'reader_instance'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'load_reader'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'reader_configs'},{'id': '80', 'type': 'dictionary_splat', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'reader_kwargs'},{'id': '82', 'type': 'except_clause', 'children': ['83', '92']},{'id': '83', 'type': 'as_pattern', 'children': ['84', '90']},{'id': '84', 'type': 'tuple', 'children': ['85', '86', '87']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'IOError'},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'yaml'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'YAMLError'},{'id': '90', 'type': 'as_pattern_target', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '92', 'type': 'block', 'children': ['93', '104', '114']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'LOG'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '98', 'type': 'argument_list', 'children': ['99', '100']},{'id': '99', 'type': 'string', 'children': [], 'value': "'Cannot use %s'"},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'reader_configs'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'LOG'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '114', 'type': 'raise_statement', 'children': []},{'id': '115', 'type': 'if_statement', 'children': ['116', '119']},{'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': 'is'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'group_keys'},{'id': '118', 'type': 'None', 'children': []},{'id': '119', 'type': 'block', 'children': ['120']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'group_keys'},{'id': '123', 'type': 'call', 'children': ['124', '129']},{'id': '124', 'type': 'attribute', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'reader_instance'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '129', 'type': 'argument_list', 'children': ['130', '131']},{'id': '130', 'type': 'string', 'children': [], 'value': "'group_keys'"},{'id': '131', 'type': 'tuple', 'children': ['132']},{'id': '132', 'type': 'string', 'children': [], 'value': "'start_time'"},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'file_keys'},{'id': '136', 'type': 'list', 'children': [], 'value': '[]'},{'id': '137', 'type': 'for_statement', 'children': ['138', '141', '146']},{'id': '138', 'type': 'pattern_list', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'filetype'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'filetype_info'},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'reader_instance'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'sorted_filetype_items'},{'id': '145', 'type': 'argument_list', 'children': []},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'for_statement', 'children': ['148', '151', '158']},{'id': '148', 'type': 'pattern_list', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'file_info'},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'reader_instance'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'filename_items_for_filetype'},{'id': '155', 'type': 'argument_list', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'files_to_sort'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'filetype_info'},{'id': '158', 'type': 'block', 'children': ['159', '174']},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'group_key'},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '164', 'type': 'generator_expression', 'children': ['165', '171']},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'file_info'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '171', 'type': 'for_in_clause', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'group_keys'},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'file_keys'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'tuple', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'group_key'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'prev_key'},{'id': '186', 'type': 'None', 'children': []},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'timedelta'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'keyword_argument', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'seconds'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'time_threshold'},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'file_groups'},{'id': '199', 'type': 'dictionary', 'children': []},{'id': '200', 'type': 'for_statement', 'children': ['201', '204', '208']},{'id': '201', 'type': 'pattern_list', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'gk'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'file_keys'},{'id': '208', 'type': 'block', 'children': ['209', '256', '288']},{'id': '209', 'type': 'if_statement', 'children': ['210', '213', '222', '244']},{'id': '210', 'type': 'comparison_operator', 'children': ['211', '212'], 'value': 'is'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'prev_key'},{'id': '212', 'type': 'None', 'children': []},{'id': '213', 'type': 'block', 'children': ['214', '218']},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'assignment', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'is_new_group'},{'id': '217', 'type': 'True', 'children': []},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'assignment', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'prev_key'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'gk'},{'id': '222', 'type': 'elif_clause', 'children': ['223', '230']},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '225', 'type': 'argument_list', 'children': ['226', '229']},{'id': '226', 'type': 'subscript', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'gk'},{'id': '228', 'type': 'integer', 'children': [], 'value': '0'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '230', 'type': 'block', 'children': ['231']},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'is_new_group'},{'id': '234', 'type': 'comparison_operator', 'children': ['235', '243'], 'value': '>'},{'id': '235', 'type': '()', 'children': ['236']},{'id': '236', 'type': 'binary_operator', 'children': ['237', '240'], 'value': '-'},{'id': '237', 'type': 'subscript', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'gk'},{'id': '239', 'type': 'integer', 'children': [], 'value': '0'},{'id': '240', 'type': 'subscript', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'prev_key'},{'id': '242', 'type': 'integer', 'children': [], 'value': '0'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '244', 'type': 'else_clause', 'children': ['245']},{'id': '245', 'type': 'block', 'children': ['246']},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'is_new_group'},{'id': '249', 'type': 'comparison_operator', 'children': ['250', '253'], 'value': '!='},{'id': '250', 'type': 'subscript', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'gk'},{'id': '252', 'type': 'integer', 'children': [], 'value': '0'},{'id': '253', 'type': 'subscript', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'prev_key'},{'id': '255', 'type': 'integer', 'children': [], 'value': '0'},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'assignment', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'vals_not_equal'},{'id': '259', 'type': 'generator_expression', 'children': ['260', '263', '280']},{'id': '260', 'type': 'comparison_operator', 'children': ['261', '262'], 'value': '!='},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'this_val'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'prev_val'},{'id': '263', 'type': 'for_in_clause', 'children': ['264', '267']},{'id': '264', 'type': 'pattern_list', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'this_val'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'prev_val'},{'id': '267', 'type': 'call', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '269', 'type': 'argument_list', 'children': ['270', '275']},{'id': '270', 'type': 'subscript', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'gk'},{'id': '272', 'type': 'slice', 'children': ['273', '274']},{'id': '273', 'type': 'integer', 'children': [], 'value': '1'},{'id': '274', 'type': 'colon', 'children': []},{'id': '275', 'type': 'subscript', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'prev_key'},{'id': '277', 'type': 'slice', 'children': ['278', '279']},{'id': '278', 'type': 'integer', 'children': [], 'value': '1'},{'id': '279', 'type': 'colon', 'children': []},{'id': '280', 'type': 'if_clause', 'children': ['281']},{'id': '281', 'type': 'boolean_operator', 'children': ['282', '285'], 'value': 'and'},{'id': '282', 'type': 'comparison_operator', 'children': ['283', '284'], 'value': 'is'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'this_val'},{'id': '284', 'type': 'None', 'children': []},{'id': '285', 'type': 'comparison_operator', 'children': ['286', '287'], 'value': 'is'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'prev_val'},{'id': '287', 'type': 'None', 'children': []},{'id': '288', 'type': 'if_statement', 'children': ['289', '295', '307']},{'id': '289', 'type': 'boolean_operator', 'children': ['290', '291'], 'value': 'or'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'is_new_group'},{'id': '291', 'type': 'call', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '293', 'type': 'argument_list', 'children': ['294']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'vals_not_equal'},{'id': '295', 'type': 'block', 'children': ['296', '303']},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'assignment', 'children': ['298', '301']},{'id': '298', 'type': 'subscript', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'file_groups'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'gk'},{'id': '301', 'type': 'list', 'children': ['302'], 'value': '[f]'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '303', 'type': 'expression_statement', 'children': ['304']},{'id': '304', 'type': 'assignment', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'prev_key'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'gk'},{'id': '307', 'type': 'else_clause', 'children': ['308']},{'id': '308', 'type': 'block', 'children': ['309']},{'id': '309', 'type': 'expression_statement', 'children': ['310']},{'id': '310', 'type': 'call', 'children': ['311', '316']},{'id': '311', 'type': 'attribute', 'children': ['312', '315']},{'id': '312', 'type': 'subscript', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'file_groups'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'prev_key'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '316', 'type': 'argument_list', 'children': ['317']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '318', 'type': 'expression_statement', 'children': ['319']},{'id': '319', 'type': 'assignment', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'sorted_group_keys'},{'id': '321', 'type': 'call', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '323', 'type': 'argument_list', 'children': ['324']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'file_groups'},{'id': '325', 'type': 'return_statement', 'children': ['326']},{'id': '326', 'type': 'list_comprehension', 'children': ['327', '333']},{'id': '327', 'type': 'dictionary', 'children': ['328']},{'id': '328', 'type': 'pair', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'reader'},{'id': '330', 'type': 'subscript', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'file_groups'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'group_key'},{'id': '333', 'type': 'for_in_clause', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'group_key'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'sorted_group_keys'} | def group_files(files_to_sort, reader=None, time_threshold=10,
group_keys=None, ppp_config_dir=None, reader_kwargs=None):
if reader is None:
raise ValueError("'reader' keyword argument is required.")
elif not isinstance(reader, (list, tuple)):
reader = [reader]
reader = reader[0]
reader_configs = list(configs_for_reader(reader, ppp_config_dir))[0]
reader_kwargs = reader_kwargs or {}
try:
reader_instance = load_reader(reader_configs, **reader_kwargs)
except (KeyError, IOError, yaml.YAMLError) as err:
LOG.info('Cannot use %s', str(reader_configs))
LOG.debug(str(err))
raise
if group_keys is None:
group_keys = reader_instance.info.get('group_keys', ('start_time',))
file_keys = []
for filetype, filetype_info in reader_instance.sorted_filetype_items():
for f, file_info in reader_instance.filename_items_for_filetype(files_to_sort, filetype_info):
group_key = tuple(file_info.get(k) for k in group_keys)
file_keys.append((group_key, f))
prev_key = None
threshold = timedelta(seconds=time_threshold)
file_groups = {}
for gk, f in sorted(file_keys):
if prev_key is None:
is_new_group = True
prev_key = gk
elif isinstance(gk[0], datetime):
is_new_group = (gk[0] - prev_key[0]) > threshold
else:
is_new_group = gk[0] != prev_key[0]
vals_not_equal = (this_val != prev_val for this_val, prev_val in zip(gk[1:], prev_key[1:])
if this_val is not None and prev_val is not None)
if is_new_group or any(vals_not_equal):
file_groups[gk] = [f]
prev_key = gk
else:
file_groups[prev_key].append(f)
sorted_group_keys = sorted(file_groups)
return [{reader: file_groups[group_key]} for group_key in sorted_group_keys] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_filetype_items'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '25']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'processed_types'},{'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': 'file_type_items'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'deque'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '24']},{'id': '17', 'type': 'attribute', 'children': ['18', '23']},{'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': 'config'},{'id': '22', 'type': 'string', 'children': [], 'value': "'file_types'"},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'while_statement', 'children': ['26', '30']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'file_type_items'},{'id': '30', 'type': 'block', 'children': ['31', '41', '50', '80', '87']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '36']},{'id': '33', 'type': 'pattern_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'filetype'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'filetype_info'},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'file_type_items'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'popleft'},{'id': '40', 'type': 'argument_list', 'children': []},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'requirements'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'filetype_info'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'string', 'children': [], 'value': "'requires'"},{'id': '50', 'type': 'if_statement', 'children': ['51', '54']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'is'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'requirements'},{'id': '53', 'type': 'None', 'children': []},{'id': '54', 'type': 'block', 'children': ['55', '67']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'missing'},{'id': '58', 'type': 'list_comprehension', 'children': ['59', '60', '63']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '60', 'type': 'for_in_clause', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'requirements'},{'id': '63', 'type': 'if_clause', 'children': ['64']},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': 'not'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'processed_types'},{'id': '67', 'type': 'if_statement', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'missing'},{'id': '69', 'type': 'block', 'children': ['70', '79']},{'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': 'file_type_items'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'tuple', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'filetype'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'filetype_info'},{'id': '79', 'type': 'continue_statement', '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': 'processed_types'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'filetype'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'yield', 'children': ['89']},{'id': '89', 'type': 'expression_list', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'filetype'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'filetype_info'} | def sorted_filetype_items(self):
processed_types = []
file_type_items = deque(self.config['file_types'].items())
while len(file_type_items):
filetype, filetype_info = file_type_items.popleft()
requirements = filetype_info.get('requires')
if requirements is not None:
missing = [req for req in requirements
if req not in processed_types]
if missing:
file_type_items.append((filetype, filetype_info))
continue
processed_types.append(filetype)
yield filetype, filetype_info |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'combine_hashes'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'hashes'},{'id': '5', 'type': 'block', 'children': ['6', '12', '33']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'hasher'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sha1'},{'id': '11', 'type': 'argument_list', 'children': []},{'id': '12', 'type': 'for_statement', 'children': ['13', '14', '18']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'hashes'},{'id': '18', 'type': 'block', 'children': ['19', '26']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'ensure_binary'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'hasher'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '33', 'type': 'return_statement', 'children': ['34']},{'id': '34', 'type': 'conditional_expression', 'children': ['35', '40', '41'], 'value': 'if'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'hasher'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'hexdigest'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'PY3'},{'id': '41', 'type': 'call', 'children': ['42', '49']},{'id': '42', 'type': 'attribute', 'children': ['43', '48']},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'hasher'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'hexdigest'},{'id': '47', 'type': 'argument_list', 'children': []},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'string', 'children': [], 'value': "'utf-8'"} | def combine_hashes(hashes):
hasher = sha1()
for h in sorted(hashes):
h = ensure_binary(h)
hasher.update(h)
return hasher.hexdigest() if PY3 else hasher.hexdigest().decode('utf-8') |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '31']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'register_jvm_tool'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19', '22', '25', '28']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'register'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'classpath_spec'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'main'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'custom_rules'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'fingerprint'},{'id': '18', 'type': 'True', 'children': []},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'classpath'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'default_parameter', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'removal_version'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'default_parameter', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'removal_hint'},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'block', 'children': ['32', '59', '67', '108', '123']},{'id': '32', 'type': 'function_definition', 'children': ['33', '34', '35']},{'id': '33', 'type': 'function_name', 'children': [], 'value': 'formulate_help'},{'id': '34', 'type': 'parameters', 'children': []},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'if_statement', 'children': ['37', '38', '50']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'classpath'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'return_statement', 'children': ['40']},{'id': '40', 'type': '()', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '47']},{'id': '42', 'type': 'attribute', 'children': ['43', '46']},{'id': '43', 'type': 'concatenated_string', 'children': ['44', '45']},{'id': '44', 'type': 'string', 'children': [], 'value': "'Target address spec for overriding the classpath of the {} jvm tool which is, '"},{'id': '45', 'type': 'string', 'children': [], 'value': "'by default: {}'"},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'classpath'},{'id': '50', 'type': 'else_clause', 'children': ['51']},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'return_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'string', 'children': [], 'value': "'Target address spec for specifying the classpath of the {} jvm tool.'"},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '62', 'type': 'boolean_operator', 'children': ['63', '64'], 'value': 'or'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'formulate_help'},{'id': '66', 'type': 'argument_list', 'children': []},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'register'},{'id': '70', 'type': 'argument_list', 'children': ['71', '77', '80', '83', '96', '99', '102', '105']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'string', 'children': [], 'value': "'--{}'"},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'advanced'},{'id': '79', 'type': 'True', 'children': []},{'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'target_option'},{'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '85', 'type': 'conditional_expression', 'children': ['86', '92', '95'], 'value': 'if'},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'string', 'children': [], 'value': "'//:{}'"},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': 'is'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'classpath_spec'},{'id': '94', 'type': 'None', 'children': []},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'classpath_spec'},{'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'fingerprint'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'fingerprint'},{'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'removal_version'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'removal_version'},{'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'removal_hint'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'removal_hint'},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'jvm_tool'},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'JvmTool'},{'id': '115', 'type': 'argument_list', 'children': ['116', '119', '120', '121', '122']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'register'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'scope'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'classpath'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'main'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'custom_rules'},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '130']},{'id': '125', 'type': 'attribute', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'JvmToolMixin'},{'id': '128', 'type': 'identifier', 'children': [], 'value': '_jvm_tools'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'jvm_tool'} | def register_jvm_tool(cls,
register,
key,
classpath_spec=None,
main=None,
custom_rules=None,
fingerprint=True,
classpath=None,
help=None,
removal_version=None,
removal_hint=None):
def formulate_help():
if classpath:
return ('Target address spec for overriding the classpath of the {} jvm tool which is, '
'by default: {}'.format(key, classpath))
else:
return 'Target address spec for specifying the classpath of the {} jvm tool.'.format(key)
help = help or formulate_help()
register('--{}'.format(key),
advanced=True,
type=target_option,
default='//:{}'.format(key) if classpath_spec is None else classpath_spec,
help=help,
fingerprint=fingerprint,
removal_version=removal_version,
removal_hint=removal_hint)
jvm_tool = cls.JvmTool(register.scope, key, classpath, main, custom_rules)
JvmToolMixin._jvm_tools.append(jvm_tool) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_available_urls'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'urls'},{'id': '6', 'type': 'block', 'children': ['7', '22', '40', '69', '84', '102', '116']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'baseurl_to_urls'},{'id': '10', 'type': 'dictionary_comprehension', 'children': ['11', '19']},{'id': '11', 'type': 'pair', 'children': ['12', '18']},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': '_baseurl'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '19', 'type': 'for_in_clause', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'urls'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'pingtimes'},{'id': '25', 'type': 'call', 'children': ['26', '31']},{'id': '26', 'type': 'attribute', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_pinger'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'pings'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'baseurl_to_urls'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '39', 'type': 'argument_list', 'children': []},{'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': '_log'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'string', 'children': [], 'value': "'Artifact cache server ping times: {}'"},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'string', 'children': [], 'value': "', '"},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'list_comprehension', 'children': ['59', '66']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'string', 'children': [], 'value': "'{}: {:.6f} secs'"},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'list_splat', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '66', 'type': 'for_in_clause', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'pingtimes'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'sorted_pingtimes'},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'pingtimes'},{'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '78', 'type': 'lambda', 'children': ['79', '81']},{'id': '79', 'type': 'lambda_parameters', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '83', 'type': 'integer', 'children': [], 'value': '1'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'available_urls'},{'id': '87', 'type': 'list_comprehension', 'children': ['88', '91', '96']},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'baseurl_to_urls'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'baseurl'},{'id': '91', 'type': 'for_in_clause', 'children': ['92', '95']},{'id': '92', 'type': 'pattern_list', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'baseurl'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'pingtime'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'sorted_pingtimes'},{'id': '96', 'type': 'if_clause', 'children': ['97']},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': '<'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'pingtime'},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'Pinger'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'UNREACHABLE'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '109']},{'id': '104', 'type': 'attribute', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '107', 'type': 'identifier', 'children': [], 'value': '_log'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'string', 'children': [], 'value': "'Available cache servers: {0}'"},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'available_urls'},{'id': '116', 'type': 'return_statement', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'available_urls'} | def get_available_urls(self, urls):
baseurl_to_urls = {self._baseurl(url): url for url in urls}
pingtimes = self._pinger.pings(list(baseurl_to_urls.keys()))
self._log.debug('Artifact cache server ping times: {}'
.format(', '.join(['{}: {:.6f} secs'.format(*p) for p in pingtimes])))
sorted_pingtimes = sorted(pingtimes, key=lambda x: x[1])
available_urls = [baseurl_to_urls[baseurl] for baseurl, pingtime in sorted_pingtimes
if pingtime < Pinger.UNREACHABLE]
self._log.debug('Available cache servers: {0}'.format(available_urls))
return available_urls |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'iterate'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'scopes'},{'id': '6', 'type': 'block', 'children': ['7', '24']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'scope_infos'},{'id': '10', 'type': 'list_comprehension', 'children': ['11', '16']},{'id': '11', 'type': 'subscript', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': '_scope_to_info'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '16', 'type': 'for_in_clause', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': '_expand_tasks'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'scopes'},{'id': '24', 'type': 'if_statement', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'scope_infos'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'for_statement', 'children': ['28', '29', '35']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'scope_info'},{'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': '_expand_subsystems'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'scope_infos'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'yield', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'scope_info'} | def iterate(self, scopes):
scope_infos = [self._scope_to_info[s] for s in self._expand_tasks(scopes)]
if scope_infos:
for scope_info in self._expand_subsystems(scope_infos):
yield scope_info |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_expand_tasks'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'scopes'},{'id': '6', 'type': 'block', 'children': ['7', '14', '67']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'expanded_scopes'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'scopes'},{'id': '14', 'type': 'for_statement', 'children': ['15', '18', '25']},{'id': '15', 'type': 'pattern_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'scope'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '18', 'type': 'call', 'children': ['19', '24']},{'id': '19', 'type': 'attribute', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': '_scope_to_info'},{'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', '34']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '31'], 'value': '=='},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'ScopeInfo'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'TASK'},{'id': '34', 'type': 'block', 'children': ['35', '42']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'outer'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'enclosing_scope'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'scope'},{'id': '42', 'type': 'while_statement', 'children': ['43', '46']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': '!='},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'outer'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'GLOBAL_SCOPE'},{'id': '46', 'type': 'block', 'children': ['47', '60']},{'id': '47', 'type': 'if_statement', 'children': ['48', '51']},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': 'in'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'outer'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'expanded_scopes'},{'id': '51', 'type': 'block', 'children': ['52', '59']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'expanded_scopes'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'scope'},{'id': '59', 'type': 'break_statement', 'children': []},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'outer'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'enclosing_scope'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'outer'},{'id': '67', 'type': 'return_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'expanded_scopes'} | def _expand_tasks(self, scopes):
expanded_scopes = set(scopes)
for scope, info in self._scope_to_info.items():
if info.category == ScopeInfo.TASK:
outer = enclosing_scope(scope)
while outer != GLOBAL_SCOPE:
if outer in expanded_scopes:
expanded_scopes.add(scope)
break
outer = enclosing_scope(outer)
return sorted(expanded_scopes) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_all'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'return_statement', 'children': ['7']},{'id': '7', 'type': 'list_comprehension', 'children': ['8', '28']},{'id': '8', 'type': 'dictionary', 'children': ['9', '14', '19']},{'id': '9', 'type': 'pair', 'children': ['10', '11']},{'id': '10', 'type': 'string', 'children': [], 'value': "'label'"},{'id': '11', 'type': 'subscript', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '13', 'type': 'integer', 'children': [], 'value': '0'},{'id': '14', 'type': 'pair', 'children': ['15', '16']},{'id': '15', 'type': 'string', 'children': [], 'value': "'timing'"},{'id': '16', 'type': 'subscript', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '18', 'type': 'integer', 'children': [], 'value': '1'},{'id': '19', 'type': 'pair', 'children': ['20', '21']},{'id': '20', 'type': 'string', 'children': [], 'value': "'is_tool'"},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '25'], 'value': 'in'},{'id': '22', 'type': 'subscript', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '24', 'type': 'integer', 'children': [], 'value': '0'},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_tool_labels'},{'id': '28', 'type': 'for_in_clause', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '32', 'type': 'argument_list', 'children': ['33', '40', '48']},{'id': '33', 'type': 'call', 'children': ['34', '39']},{'id': '34', 'type': 'attribute', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': '_timings_by_path'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '42', 'type': 'lambda', 'children': ['43', '45']},{'id': '43', 'type': 'lambda_parameters', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '45', 'type': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '47', 'type': 'integer', 'children': [], 'value': '1'},{'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '50', 'type': 'True', 'children': []} | def get_all(self):
return [{'label': x[0], 'timing': x[1], 'is_tool': x[0] in self._tool_labels}
for x in sorted(self._timings_by_path.items(), key=lambda x: x[1], reverse=True)] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'all'},{'id': '3', 'type': 'parameters', 'children': []},{'id': '4', 'type': 'block', 'children': ['5']},{'id': '5', 'type': 'return_statement', 'children': ['6']},{'id': '6', 'type': 'list_comprehension', 'children': ['7', '8', '22']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'goal'},{'id': '8', 'type': 'for_in_clause', 'children': ['9', '12']},{'id': '9', 'type': 'pattern_list', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'goal'},{'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': 'Goal'},{'id': '19', 'type': 'identifier', 'children': [], 'value': '_goal_by_name'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '21', 'type': 'argument_list', 'children': []},{'id': '22', 'type': 'if_clause', 'children': ['23']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'goal'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'active'} | def all():
return [goal for _, goal in sorted(Goal._goal_by_name.items()) if goal.active] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'select_best_url'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '14']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'best_url'},{'id': '9', 'type': 'subscript', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'parsed_urls'},{'id': '13', 'type': 'integer', 'children': [], 'value': '0'},{'id': '14', 'type': 'try_statement', 'children': ['15', '19', '60']},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'yield', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'best_url'},{'id': '19', 'type': 'except_clause', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '21', 'type': 'block', 'children': ['22', '30', '59']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'augmented_assignment', 'children': ['24', '29'], 'value': '+='},{'id': '24', 'type': 'subscript', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'unsuccessful_calls'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'best_url'},{'id': '29', 'type': 'integer', 'children': [], 'value': '1'},{'id': '30', 'type': 'if_statement', 'children': ['31', '40']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '37'], 'value': '>'},{'id': '32', 'type': 'subscript', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'unsuccessful_calls'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'best_url'},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'max_failures'},{'id': '40', 'type': 'block', 'children': ['41', '51']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '48']},{'id': '43', 'type': 'attribute', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'parsed_urls'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'rotate'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'unary_operator', 'children': ['50'], 'value': '-'},{'id': '50', 'type': 'integer', 'children': [], 'value': '1'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '58']},{'id': '53', 'type': 'subscript', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'unsuccessful_calls'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'best_url'},{'id': '58', 'type': 'integer', 'children': [], 'value': '0'},{'id': '59', 'type': 'raise_statement', 'children': []},{'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', '69']},{'id': '64', 'type': 'subscript', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'unsuccessful_calls'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'best_url'},{'id': '69', 'type': 'integer', 'children': [], 'value': '0'} | def select_best_url(self):
best_url = self.parsed_urls[0]
try:
yield best_url
except Exception:
self.unsuccessful_calls[best_url] += 1
if self.unsuccessful_calls[best_url] > self.max_failures:
self.parsed_urls.rotate(-1)
self.unsuccessful_calls[best_url] = 0
raise
else:
self.unsuccessful_calls[best_url] = 0 |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_topological_sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'targets'},{'id': '6', 'type': 'block', 'children': ['7', '14']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'target_set'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'targets'},{'id': '14', 'type': 'return_statement', 'children': ['15']},{'id': '15', 'type': 'list_comprehension', 'children': ['16', '17', '26']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '17', 'type': 'for_in_clause', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'reversed'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'sort_targets'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'targets'},{'id': '26', 'type': 'if_clause', 'children': ['27']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'in'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'target_set'} | def _topological_sort(self, targets):
target_set = set(targets)
return [t for t in reversed(sort_targets(targets)) if t in target_set] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sortmerna_detailed_barplot'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '12', '18', '53', '72', '85']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '11', 'type': 'argument_list', 'children': []},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'metrics'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '17', 'type': 'argument_list', 'children': []},{'id': '18', 'type': 'for_statement', 'children': ['19', '20', '23']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'sample'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'sortmerna'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'for_statement', 'children': ['25', '26', '31']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '26', 'type': 'subscript', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'sortmerna'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'sample'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'if_statement', 'children': ['33', '45']},{'id': '33', 'type': 'boolean_operator', 'children': ['34', '41'], 'value': 'and'},{'id': '34', 'type': 'not_operator', 'children': ['35']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'in'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '37', 'type': 'list', 'children': ['38', '39', '40'], 'value': '["total", "rRNA", "non_rRNA"]'},{'id': '38', 'type': 'string', 'children': [], 'value': '"total"'},{'id': '39', 'type': 'string', 'children': [], 'value': '"rRNA"'},{'id': '40', 'type': 'string', 'children': [], 'value': '"non_rRNA"'},{'id': '41', 'type': 'not_operator', 'children': ['42']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'in'},{'id': '43', 'type': 'string', 'children': [], 'value': '"_pct"'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'metrics'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '53', 'type': 'for_statement', 'children': ['54', '55', '56']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'metrics'},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '62']},{'id': '59', 'type': 'subscript', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '62', 'type': 'dictionary', 'children': ['63']},{'id': '63', 'type': 'pair', 'children': ['64', '65']},{'id': '64', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'string', 'children': [], 'value': '"_count"'},{'id': '71', 'type': 'string', 'children': [], 'value': '""'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'pconfig'},{'id': '75', 'type': 'dictionary', 'children': ['76', '79', '82']},{'id': '76', 'type': 'pair', 'children': ['77', '78']},{'id': '77', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '78', 'type': 'string', 'children': [], 'value': "'sortmerna-detailed-plot'"},{'id': '79', 'type': 'pair', 'children': ['80', '81']},{'id': '80', 'type': 'string', 'children': [], 'value': "'title'"},{'id': '81', 'type': 'string', 'children': [], 'value': "'SortMeRNA: Hit Counts'"},{'id': '82', 'type': 'pair', 'children': ['83', '84']},{'id': '83', 'type': 'string', 'children': [], 'value': "'ylab'"},{'id': '84', 'type': 'string', 'children': [], 'value': "'Reads'"},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'add_section'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'plot'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'bargraph'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'plot'},{'id': '97', 'type': 'argument_list', 'children': ['98', '101', '102']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'sortmerna'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'pconfig'} | def sortmerna_detailed_barplot (self):
keys = OrderedDict()
metrics = set()
for sample in self.sortmerna:
for key in self.sortmerna[sample]:
if not key in ["total", "rRNA", "non_rRNA"] and not "_pct" in key:
metrics.add(key)
for key in metrics:
keys[key] = { 'name': key.replace("_count","") }
pconfig = {
'id': 'sortmerna-detailed-plot',
'title': 'SortMeRNA: Hit Counts',
'ylab': 'Reads'
}
self.add_section( plot = bargraph.plot(self.sortmerna, keys, pconfig) ) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_short_chrom'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '6', 'type': 'block', 'children': ['7', '15', '33', '43', '68']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'default_allowed'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'list', 'children': ['14'], 'value': '["X"]'},{'id': '14', 'type': 'string', 'children': [], 'value': '"X"'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'allowed_chroms'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '30']},{'id': '22', 'type': 'attribute', 'children': ['23', '29']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27', '28']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '27', 'type': 'string', 'children': [], 'value': '"goleft_indexcov_config"'},{'id': '28', 'type': 'dictionary', 'children': []},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32']},{'id': '31', 'type': 'string', 'children': [], 'value': '"chromosomes"'},{'id': '32', 'type': 'list', 'children': [], 'value': '[]'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'chrom_clean'},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42']},{'id': '41', 'type': 'string', 'children': [], 'value': '"chr"'},{'id': '42', 'type': 'string', 'children': [], 'value': '""'},{'id': '43', 'type': 'try_statement', 'children': ['44', '52']},{'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': 'chrom_clean'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'chrom_clean'},{'id': '52', 'type': 'except_clause', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'if_statement', 'children': ['56', '63']},{'id': '56', 'type': 'boolean_operator', 'children': ['57', '60'], 'value': 'and'},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': 'not'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'chrom_clean'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'default_allowed'},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'not'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'chrom_clean'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'allowed_chroms'},{'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': 'chrom_clean'},{'id': '67', 'type': 'None', 'children': []},{'id': '68', 'type': 'if_statement', 'children': ['69', '70', '82']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'allowed_chroms'},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'if_statement', 'children': ['72', '79']},{'id': '72', 'type': 'boolean_operator', 'children': ['73', '76'], 'value': 'or'},{'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': 'in'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'allowed_chroms'},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': 'in'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'chrom_clean'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'allowed_chroms'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'return_statement', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'chrom_clean'},{'id': '82', 'type': 'elif_clause', 'children': ['83', '92']},{'id': '83', 'type': 'boolean_operator', 'children': ['84', '89'], 'value': 'or'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'chrom_clean'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': 'in'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'chrom_clean'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'default_allowed'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'return_statement', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'chrom_clean'} | def _short_chrom(self, chrom):
default_allowed = set(["X"])
allowed_chroms = set(getattr(config, "goleft_indexcov_config", {}).get("chromosomes", []))
chrom_clean = chrom.replace("chr", "")
try:
chrom_clean = int(chrom_clean)
except ValueError:
if chrom_clean not in default_allowed and chrom_clean not in allowed_chroms:
chrom_clean = None
if allowed_chroms:
if chrom in allowed_chroms or chrom_clean in allowed_chroms:
return chrom_clean
elif isinstance(chrom_clean, int) or chrom_clean in default_allowed:
return chrom_clean |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'deepvalues'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '5', 'type': 'block', 'children': ['6', '13']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'vals_sorted_by_key'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '13', 'type': 'for_statement', 'children': ['14', '15', '16']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '16', 'type': 'block', 'children': ['17', '21', '47']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '20', 'type': 'False', 'children': []},{'id': '21', 'type': 'try_statement', 'children': ['22', '27', '31']},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '27', 'type': 'except_clause', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'pass_statement', 'children': []},{'id': '31', 'type': 'else_clause', 'children': ['32']},{'id': '32', 'type': 'block', 'children': ['33', '37']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '36', 'type': 'True', 'children': []},{'id': '37', 'type': 'for_statement', 'children': ['38', '39', '43']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'subobj'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'deepvalues'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'yield', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'subobj'},{'id': '47', 'type': 'if_statement', 'children': ['48', '50']},{'id': '48', 'type': 'not_operator', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'yield', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'obj'} | def deepvalues(mapping):
values = vals_sorted_by_key(mapping)
for obj in values:
mapping = False
try:
obj.items
except AttributeError:
pass
else:
mapping = True
for subobj in deepvalues(obj):
yield subobj
if not mapping:
yield obj |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'values'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'return_statement', 'children': ['7']},{'id': '7', 'type': 'list_comprehension', 'children': ['8', '17']},{'id': '8', 'type': 'call', 'children': ['9', '14']},{'id': '9', 'type': 'attribute', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'policy'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'header_fetch_parse'},{'id': '14', 'type': 'argument_list', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '17', 'type': 'for_in_clause', 'children': ['18', '21']},{'id': '18', 'type': 'pattern_list', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': '_headers'} | def values(self):
return [self.policy.header_fetch_parse(k, v)
for k, v in self._headers] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'items'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'return_statement', 'children': ['7']},{'id': '7', 'type': 'list_comprehension', 'children': ['8', '19']},{'id': '8', 'type': 'tuple', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '10', 'type': 'call', 'children': ['11', '16']},{'id': '11', 'type': 'attribute', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'policy'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'header_fetch_parse'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '19', 'type': 'for_in_clause', 'children': ['20', '23']},{'id': '20', 'type': 'pattern_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': '_headers'} | def items(self):
return [(k, self.policy.header_fetch_parse(k, v))
for k, v in self._headers] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_all'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'failobj'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '14', '22', '54', '60']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '13', 'type': 'list', 'children': [], 'value': '[]'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '21', 'type': 'argument_list', 'children': []},{'id': '22', 'type': 'for_statement', 'children': ['23', '26', '29']},{'id': '23', 'type': 'pattern_list', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': '_headers'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'if_statement', 'children': ['31', '38']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '37'], 'value': '=='},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '36', 'type': 'argument_list', 'children': []},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '44', 'type': 'argument_list', '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': 'policy'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'header_fetch_parse'},{'id': '51', 'type': 'argument_list', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '54', 'type': 'if_statement', 'children': ['55', '57']},{'id': '55', 'type': 'not_operator', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'return_statement', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'failobj'},{'id': '60', 'type': 'return_statement', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'values'} | def get_all(self, name, failobj=None):
values = []
name = name.lower()
for k, v in self._headers:
if k.lower() == name:
values.append(self.policy.header_fetch_parse(k, v))
if not values:
return failobj
return values |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'setup'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'input_file_id'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'down_checkpoints'},{'id': '8', 'type': 'block', 'children': ['9', '18']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'call', 'children': ['11', '16']},{'id': '11', 'type': 'attribute', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'logToMaster'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'string', 'children': [], 'value': '"Starting the merge sort"'},{'id': '18', 'type': 'return_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '36']},{'id': '20', 'type': 'attribute', 'children': ['21', '35']},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'addChildJobFn'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27', '28', '29', '32']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'down'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'input_file_id'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'down_checkpoints'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'down_checkpoints'},{'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '34', 'type': 'string', 'children': [], 'value': "'600M'"},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '36', 'type': 'argument_list', 'children': []} | def setup(job, input_file_id, n, down_checkpoints):
job.fileStore.logToMaster("Starting the merge sort")
return job.addChildJobFn(down,
input_file_id, n,
down_checkpoints=down_checkpoints,
memory='600M').rv() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'down'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'input_file_id'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'down_checkpoints'},{'id': '8', 'type': 'block', 'children': ['9', '23', '34']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'input_file'},{'id': '12', 'type': 'call', 'children': ['13', '18']},{'id': '13', 'type': 'attribute', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'readGlobalFile'},{'id': '18', 'type': 'argument_list', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'input_file_id'},{'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'cache'},{'id': '22', 'type': 'False', 'children': []},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '26', 'type': 'call', 'children': ['27', '32']},{'id': '27', 'type': 'attribute', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'getsize'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'input_file'},{'id': '34', 'type': 'if_statement', 'children': ['35', '38', '191']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': '>'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '38', 'type': 'block', 'children': ['39', '57', '66', '76', '98', '108', '130']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '46']},{'id': '41', 'type': 'attribute', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'logToMaster'},{'id': '46', 'type': 'argument_list', 'children': ['47', '52']},{'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '%'},{'id': '48', 'type': 'string', 'children': [], 'value': '"Splitting file: %s of size: %s"'},{'id': '49', 'type': 'tuple', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'input_file_id'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'CRITICAL'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'mid_point'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'get_midpoint'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64', '65']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'input_file'},{'id': '64', 'type': 'integer', 'children': [], 'value': '0'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 't1'},{'id': '69', 'type': 'call', 'children': ['70', '75']},{'id': '70', 'type': 'attribute', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'getLocalTempFile'},{'id': '75', 'type': 'argument_list', 'children': []},{'id': '76', 'type': 'with_statement', 'children': ['77', '87']},{'id': '77', 'type': 'with_clause', 'children': ['78']},{'id': '78', 'type': 'with_item', 'children': ['79']},{'id': '79', 'type': 'as_pattern', 'children': ['80', '85']},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '82', 'type': 'argument_list', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 't1'},{'id': '84', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '85', 'type': 'as_pattern_target', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'fH'},{'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': 'copy_subrange_of_file'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93', '94', '97']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'input_file'},{'id': '93', 'type': 'integer', 'children': [], 'value': '0'},{'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '+'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'mid_point'},{'id': '96', 'type': 'integer', 'children': [], 'value': '1'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'fH'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 't2'},{'id': '101', 'type': 'call', 'children': ['102', '107']},{'id': '102', 'type': 'attribute', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'getLocalTempFile'},{'id': '107', 'type': 'argument_list', 'children': []},{'id': '108', 'type': 'with_statement', 'children': ['109', '119']},{'id': '109', 'type': 'with_clause', 'children': ['110']},{'id': '110', 'type': 'with_item', 'children': ['111']},{'id': '111', 'type': 'as_pattern', 'children': ['112', '117']},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '114', 'type': 'argument_list', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 't2'},{'id': '116', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '117', 'type': 'as_pattern_target', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'fH'},{'id': '119', 'type': 'block', 'children': ['120']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'copy_subrange_of_file'},{'id': '123', 'type': 'argument_list', 'children': ['124', '125', '128', '129']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'input_file'},{'id': '125', 'type': 'binary_operator', 'children': ['126', '127'], 'value': '+'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'mid_point'},{'id': '127', 'type': 'integer', 'children': [], 'value': '1'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'fH'},{'id': '130', 'type': 'return_statement', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '190']},{'id': '132', 'type': 'attribute', 'children': ['133', '189']},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'addFollowOnJobFn'},{'id': '137', 'type': 'argument_list', 'children': ['138', '139', '164']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'up'},{'id': '139', 'type': 'call', 'children': ['140', '163']},{'id': '140', 'type': 'attribute', 'children': ['141', '162']},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'addChildJobFn'},{'id': '145', 'type': 'argument_list', 'children': ['146', '147', '155', '156', '159']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'down'},{'id': '147', 'type': 'call', 'children': ['148', '153']},{'id': '148', 'type': 'attribute', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'writeGlobalFile'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 't1'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '156', 'type': 'keyword_argument', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'down_checkpoints'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'down_checkpoints'},{'id': '159', 'type': 'keyword_argument', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '161', 'type': 'string', 'children': [], 'value': "'600M'"},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '163', 'type': 'argument_list', 'children': []},{'id': '164', 'type': 'call', 'children': ['165', '188']},{'id': '165', 'type': 'attribute', 'children': ['166', '187']},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'addChildJobFn'},{'id': '170', 'type': 'argument_list', 'children': ['171', '172', '180', '181', '184']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'down'},{'id': '172', 'type': 'call', 'children': ['173', '178']},{'id': '173', 'type': 'attribute', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'writeGlobalFile'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 't2'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '181', 'type': 'keyword_argument', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'down_checkpoints'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'down_checkpoints'},{'id': '184', 'type': 'keyword_argument', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '186', 'type': 'string', 'children': [], 'value': "'600M'"},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '188', 'type': 'argument_list', 'children': []},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '190', 'type': 'argument_list', 'children': []},{'id': '191', 'type': 'else_clause', 'children': ['192']},{'id': '192', 'type': 'block', 'children': ['193', '211', '221', '227']},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'call', 'children': ['195', '200']},{'id': '195', 'type': 'attribute', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'logToMaster'},{'id': '200', 'type': 'argument_list', 'children': ['201', '206']},{'id': '201', 'type': 'binary_operator', 'children': ['202', '203'], 'value': '%'},{'id': '202', 'type': 'string', 'children': [], 'value': '"Sorting file: %s of size: %s"'},{'id': '203', 'type': 'tuple', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'input_file_id'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '206', 'type': 'keyword_argument', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'CRITICAL'},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'output_file'},{'id': '214', 'type': 'call', 'children': ['215', '220']},{'id': '215', 'type': 'attribute', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'getLocalTempFile'},{'id': '220', 'type': 'argument_list', 'children': []},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '224', 'type': 'argument_list', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'input_file'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'output_file'},{'id': '227', 'type': 'return_statement', 'children': ['228']},{'id': '228', 'type': 'call', 'children': ['229', '234']},{'id': '229', 'type': 'attribute', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'writeGlobalFile'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'output_file'} | def down(job, input_file_id, n, down_checkpoints):
input_file = job.fileStore.readGlobalFile(input_file_id, cache=False)
length = os.path.getsize(input_file)
if length > n:
job.fileStore.logToMaster("Splitting file: %s of size: %s"
% (input_file_id, length), level=logging.CRITICAL)
mid_point = get_midpoint(input_file, 0, length)
t1 = job.fileStore.getLocalTempFile()
with open(t1, 'w') as fH:
copy_subrange_of_file(input_file, 0, mid_point + 1, fH)
t2 = job.fileStore.getLocalTempFile()
with open(t2, 'w') as fH:
copy_subrange_of_file(input_file, mid_point + 1, length, fH)
return job.addFollowOnJobFn(up, job.addChildJobFn(down, job.fileStore.writeGlobalFile(t1), n,
down_checkpoints=down_checkpoints, memory='600M').rv(),
job.addChildJobFn(down, job.fileStore.writeGlobalFile(t2), n,
down_checkpoints=down_checkpoints,
memory='600M').rv()).rv()
else:
job.fileStore.logToMaster("Sorting file: %s of size: %s"
% (input_file_id, length), level=logging.CRITICAL)
output_file = job.fileStore.getLocalTempFile()
sort(input_file, output_file)
return job.fileStore.writeGlobalFile(output_file) |
{'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': 'in_file'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '6', 'type': 'block', 'children': ['7', '15', '23', '29', '35', '43', '54']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'filehandle'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '12', 'type': 'argument_list', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'in_file'},{'id': '14', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'filehandle'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'readlines'},{'id': '22', 'type': 'argument_list', 'children': []},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'filehandle'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '28', 'type': 'argument_list', 'children': []},{'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': 'lines'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '34', 'type': 'argument_list', 'children': []},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'filehandle'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '42', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '43', 'type': 'for_statement', 'children': ['44', '45', '46']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'filehandle'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'filehandle'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '59', 'type': 'argument_list', 'children': []} | def sort(in_file, out_file):
filehandle = open(in_file, 'r')
lines = filehandle.readlines()
filehandle.close()
lines.sort()
filehandle = open(out_file, 'w')
for line in lines:
filehandle.write(line)
filehandle.close() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'filehandle_1'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'filehandle_2'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'output_filehandle'},{'id': '7', 'type': 'block', 'children': ['8', '16', '55']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'line2'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'filehandle_2'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'for_statement', 'children': ['17', '18', '23']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'line1'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'filehandle_1'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'readlines'},{'id': '22', 'type': 'argument_list', 'children': []},{'id': '23', 'type': 'block', 'children': ['24', '48']},{'id': '24', 'type': 'while_statement', 'children': ['25', '32']},{'id': '25', 'type': 'boolean_operator', 'children': ['26', '29'], 'value': 'and'},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': '!='},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'line2'},{'id': '28', 'type': 'string', 'children': [], 'value': "''"},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': '<='},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'line2'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'line1'},{'id': '32', 'type': 'block', 'children': ['33', '40']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'output_filehandle'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'line2'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'line2'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'filehandle_2'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '47', 'type': 'argument_list', 'children': []},{'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': 'output_filehandle'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'line1'},{'id': '55', 'type': 'while_statement', 'children': ['56', '59']},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': '!='},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'line2'},{'id': '58', 'type': 'string', 'children': [], 'value': "''"},{'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': 'output_filehandle'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'line2'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'line2'},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'filehandle_2'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '74', 'type': 'argument_list', 'children': []} | def merge(filehandle_1, filehandle_2, output_filehandle):
line2 = filehandle_2.readline()
for line1 in filehandle_1.readlines():
while line2 != '' and line2 <= line1:
output_filehandle.write(line2)
line2 = filehandle_2.readline()
output_filehandle.write(line1)
while line2 != '':
output_filehandle.write(line2)
line2 = filehandle_2.readline() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'decorateSubHeader'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'columnWidths'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '7', 'type': 'block', 'children': ['8', '16']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'if_statement', 'children': ['17', '22', '71']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': '!='},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sortCategory'},{'id': '22', 'type': 'block', 'children': ['23', '69']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '26', 'type': 'binary_operator', 'children': ['27', '28'], 'value': '%'},{'id': '27', 'type': 'string', 'children': [], 'value': '"| %*s%*s%*s%*s%*s "'},{'id': '28', 'type': 'tuple', 'children': ['29', '36', '37', '44', '45', '52', '53', '60', '61', '68']},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'columnWidths'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'getWidth'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '35', 'type': 'string', 'children': [], 'value': '"min"'},{'id': '36', 'type': 'string', 'children': [], 'value': '"min"'},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'columnWidths'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'getWidth'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '43', 'type': 'string', 'children': [], 'value': '"med"'},{'id': '44', 'type': 'string', 'children': [], 'value': '"med"'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'columnWidths'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'getWidth'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '51', 'type': 'string', 'children': [], 'value': '"ave"'},{'id': '52', 'type': 'string', 'children': [], 'value': '"ave"'},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'columnWidths'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'getWidth'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '59', 'type': 'string', 'children': [], 'value': '"max"'},{'id': '60', 'type': 'string', 'children': [], 'value': '"max"'},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'columnWidths'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'getWidth'},{'id': '65', 'type': 'argument_list', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '67', 'type': 'string', 'children': [], 'value': '"total"'},{'id': '68', 'type': 'string', 'children': [], 'value': '"total"'},{'id': '69', 'type': 'return_statement', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '71', 'type': 'else_clause', 'children': ['72']},{'id': '72', 'type': 'block', 'children': ['73', '77', '155', '159']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '76', 'type': 'string', 'children': [], 'value': '"| "'},{'id': '77', 'type': 'for_statement', 'children': ['78', '81', '127']},{'id': '78', 'type': 'pattern_list', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '81', 'type': 'list', 'children': ['82', '91', '100', '109', '118'], 'value': '[("min", columnWidths.getWidth(title, "min")),\n ("med", columnWidths.getWidth(title, "med")),\n ("ave", columnWidths.getWidth(title, "ave")),\n ("max", columnWidths.getWidth(title, "max")),\n ("total", columnWidths.getWidth(title, "total"))]'},{'id': '82', 'type': 'tuple', 'children': ['83', '84']},{'id': '83', 'type': 'string', 'children': [], 'value': '"min"'},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'columnWidths'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'getWidth'},{'id': '88', 'type': 'argument_list', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '90', 'type': 'string', 'children': [], 'value': '"min"'},{'id': '91', 'type': 'tuple', 'children': ['92', '93']},{'id': '92', 'type': 'string', 'children': [], 'value': '"med"'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'columnWidths'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'getWidth'},{'id': '97', 'type': 'argument_list', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '99', 'type': 'string', 'children': [], 'value': '"med"'},{'id': '100', 'type': 'tuple', 'children': ['101', '102']},{'id': '101', 'type': 'string', 'children': [], 'value': '"ave"'},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'columnWidths'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'getWidth'},{'id': '106', 'type': 'argument_list', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '108', 'type': 'string', 'children': [], 'value': '"ave"'},{'id': '109', 'type': 'tuple', 'children': ['110', '111']},{'id': '110', 'type': 'string', 'children': [], 'value': '"max"'},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'columnWidths'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'getWidth'},{'id': '115', 'type': 'argument_list', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '117', 'type': 'string', 'children': [], 'value': '"max"'},{'id': '118', 'type': 'tuple', 'children': ['119', '120']},{'id': '119', 'type': 'string', 'children': [], 'value': '"total"'},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'columnWidths'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'getWidth'},{'id': '124', 'type': 'argument_list', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '126', 'type': 'string', 'children': [], 'value': '"total"'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'if_statement', 'children': ['129', '134', '145']},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '133'], 'value': '=='},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'sortField'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'augmented_assignment', 'children': ['137', '138'], 'value': '+='},{'id': '137', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '138', 'type': 'binary_operator', 'children': ['139', '140'], 'value': '%'},{'id': '139', 'type': 'string', 'children': [], 'value': '"%*s*"'},{'id': '140', 'type': 'tuple', 'children': ['141', '144']},{'id': '141', 'type': 'binary_operator', 'children': ['142', '143'], 'value': '-'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '143', 'type': 'integer', 'children': [], 'value': '1'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '145', 'type': 'else_clause', 'children': ['146']},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'augmented_assignment', 'children': ['149', '150'], 'value': '+='},{'id': '149', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '150', 'type': 'binary_operator', 'children': ['151', '152'], 'value': '%'},{'id': '151', 'type': 'string', 'children': [], 'value': '"%*s"'},{'id': '152', 'type': 'tuple', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'augmented_assignment', 'children': ['157', '158'], 'value': '+='},{'id': '157', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '158', 'type': 'string', 'children': [], 'value': '" "'},{'id': '159', 'type': 'return_statement', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 's'} | def decorateSubHeader(title, columnWidths, options):
title = title.lower()
if title != options.sortCategory:
s = "| %*s%*s%*s%*s%*s " % (
columnWidths.getWidth(title, "min"), "min",
columnWidths.getWidth(title, "med"), "med",
columnWidths.getWidth(title, "ave"), "ave",
columnWidths.getWidth(title, "max"), "max",
columnWidths.getWidth(title, "total"), "total")
return s
else:
s = "| "
for field, width in [("min", columnWidths.getWidth(title, "min")),
("med", columnWidths.getWidth(title, "med")),
("ave", columnWidths.getWidth(title, "ave")),
("max", columnWidths.getWidth(title, "max")),
("total", columnWidths.getWidth(title, "total"))]:
if options.sortField == field:
s += "%*s*" % (width - 1, field)
else:
s += "%*s" % (width, field)
s += " "
return s |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sortJobs'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'jobTypes'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '6', 'type': 'block', 'children': ['7', '26', '34']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'longforms'},{'id': '10', 'type': 'dictionary', 'children': ['11', '14', '17', '20', '23']},{'id': '11', 'type': 'pair', 'children': ['12', '13']},{'id': '12', 'type': 'string', 'children': [], 'value': '"med"'},{'id': '13', 'type': 'string', 'children': [], 'value': '"median"'},{'id': '14', 'type': 'pair', 'children': ['15', '16']},{'id': '15', 'type': 'string', 'children': [], 'value': '"ave"'},{'id': '16', 'type': 'string', 'children': [], 'value': '"average"'},{'id': '17', 'type': 'pair', 'children': ['18', '19']},{'id': '18', 'type': 'string', 'children': [], 'value': '"min"'},{'id': '19', 'type': 'string', 'children': [], 'value': '"min"'},{'id': '20', 'type': 'pair', 'children': ['21', '22']},{'id': '21', 'type': 'string', 'children': [], 'value': '"total"'},{'id': '22', 'type': 'string', 'children': [], 'value': '"total"'},{'id': '23', 'type': 'pair', 'children': ['24', '25']},{'id': '24', 'type': 'string', 'children': [], 'value': '"max"'},{'id': '25', 'type': 'string', 'children': [], 'value': '"max"'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'sortField'},{'id': '29', 'type': 'subscript', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'longforms'},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'sortField'},{'id': '34', 'type': 'if_statement', 'children': ['35', '59', '86', '111']},{'id': '35', 'type': '()', 'children': ['36']},{'id': '36', 'type': 'boolean_operator', 'children': ['37', '54'], 'value': 'or'},{'id': '37', 'type': 'boolean_operator', 'children': ['38', '49'], 'value': 'or'},{'id': '38', 'type': 'boolean_operator', 'children': ['39', '44'], 'value': 'or'},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '43'], 'value': '=='},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'sortCategory'},{'id': '43', 'type': 'string', 'children': [], 'value': '"time"'},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '48'], 'value': '=='},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'sortCategory'},{'id': '48', 'type': 'string', 'children': [], 'value': '"clock"'},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '53'], 'value': '=='},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'sortCategory'},{'id': '53', 'type': 'string', 'children': [], 'value': '"wait"'},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '58'], 'value': '=='},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'sortCategory'},{'id': '58', 'type': 'string', 'children': [], 'value': '"memory"'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'return_statement', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65', '81']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'jobTypes'},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '67', 'type': 'lambda', 'children': ['68', '70']},{'id': '68', 'type': 'lambda_parameters', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '74', 'type': 'binary_operator', 'children': ['75', '76'], 'value': '%'},{'id': '75', 'type': 'string', 'children': [], 'value': '"%s_%s"'},{'id': '76', 'type': 'tuple', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'sortField'},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'sortCategory'},{'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'sortReverse'},{'id': '86', 'type': 'elif_clause', 'children': ['87', '92']},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '91'], 'value': '=='},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'sortCategory'},{'id': '91', 'type': 'string', 'children': [], 'value': '"alpha"'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'return_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '96', 'type': 'argument_list', 'children': ['97', '98', '106']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'jobTypes'},{'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '100', 'type': 'lambda', 'children': ['101', '103']},{'id': '101', 'type': 'lambda_parameters', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '106', 'type': 'keyword_argument', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'sortReverse'},{'id': '111', 'type': 'elif_clause', 'children': ['112', '117']},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '116'], 'value': '=='},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'sortCategory'},{'id': '116', 'type': 'string', 'children': [], 'value': '"count"'},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'return_statement', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '121', 'type': 'argument_list', 'children': ['122', '123', '131']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'jobTypes'},{'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '125', 'type': 'lambda', 'children': ['126', '128']},{'id': '126', 'type': 'lambda_parameters', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'total_number'},{'id': '131', 'type': 'keyword_argument', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'sortReverse'} | def sortJobs(jobTypes, options):
longforms = {"med": "median",
"ave": "average",
"min": "min",
"total": "total",
"max": "max",}
sortField = longforms[options.sortField]
if (options.sortCategory == "time" or
options.sortCategory == "clock" or
options.sortCategory == "wait" or
options.sortCategory == "memory"
):
return sorted(
jobTypes,
key=lambda tag: getattr(tag, "%s_%s"
% (sortField, options.sortCategory)),
reverse=options.sortReverse)
elif options.sortCategory == "alpha":
return sorted(
jobTypes, key=lambda tag: tag.name,
reverse=options.sortReverse)
elif options.sortCategory == "count":
return sorted(jobTypes, key=lambda tag: tag.total_number,
reverse=options.sortReverse) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort_tau_by_y'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '6', 'type': 'block', 'children': ['7', '17', '25', '38', '53', '61', '72', '84', '104']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'tau_y'},{'id': '10', 'type': 'subscript', 'children': ['11', '14', '16']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'tau_matrix'},{'id': '14', 'type': 'slice', 'children': ['15']},{'id': '15', 'type': 'colon', 'children': []},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '22']},{'id': '19', 'type': 'subscript', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'tau_y'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'NaN'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'temp'},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'empty'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'list', 'children': ['34', '37'], 'value': '[self.n_nodes, 3]'},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'n_nodes'},{'id': '37', 'type': 'integer', 'children': [], 'value': '3'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '45']},{'id': '40', 'type': 'subscript', 'children': ['41', '42', '44']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'temp'},{'id': '42', 'type': 'slice', 'children': ['43']},{'id': '43', 'type': 'colon', 'children': []},{'id': '44', 'type': 'integer', 'children': [], 'value': '0'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'n_nodes'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '60']},{'id': '55', 'type': 'subscript', 'children': ['56', '57', '59']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'temp'},{'id': '57', 'type': 'slice', 'children': ['58']},{'id': '58', 'type': 'colon', 'children': []},{'id': '59', 'type': 'integer', 'children': [], 'value': '1'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'tau_y'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '68']},{'id': '63', 'type': 'subscript', 'children': ['64', '65', '67']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'temp'},{'id': '65', 'type': 'slice', 'children': ['66']},{'id': '66', 'type': 'colon', 'children': []},{'id': '67', 'type': 'integer', 'children': [], 'value': '2'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'tau_y'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '82']},{'id': '74', 'type': 'subscript', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'temp'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'isnan'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'temp'},{'id': '82', 'type': 'unary_operator', 'children': ['83'], 'value': '-'},{'id': '83', 'type': 'integer', 'children': [], 'value': '10'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'tau_sorted'},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'temp'},{'id': '89', 'type': 'subscript', 'children': ['90', '99']},{'id': '90', 'type': 'call', 'children': ['91', '98']},{'id': '91', 'type': 'attribute', 'children': ['92', '97']},{'id': '92', 'type': 'subscript', 'children': ['93', '94', '96']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'temp'},{'id': '94', 'type': 'slice', 'children': ['95']},{'id': '95', 'type': 'colon', 'children': []},{'id': '96', 'type': 'integer', 'children': [], 'value': '2'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '98', 'type': 'argument_list', 'children': []},{'id': '99', 'type': 'slice', 'children': ['100', '101', '102']},{'id': '100', 'type': 'colon', 'children': []},{'id': '101', 'type': 'colon', 'children': []},{'id': '102', 'type': 'unary_operator', 'children': ['103'], 'value': '-'},{'id': '103', 'type': 'integer', 'children': [], 'value': '1'},{'id': '104', 'type': 'return_statement', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'tau_sorted'} | def _sort_tau_by_y(self, y):
tau_y = self.tau_matrix[:, y]
tau_y[y] = np.NaN
temp = np.empty([self.n_nodes, 3])
temp[:, 0] = np.arange(self.n_nodes)
temp[:, 1] = tau_y
temp[:, 2] = abs(tau_y)
temp[np.isnan(temp)] = -10
tau_sorted = temp[temp[:, 2].argsort()[::-1]]
return tau_sorted |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_edge'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'return_statement', 'children': ['7']},{'id': '7', 'type': 'call', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '9', 'type': 'argument_list', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '11', 'type': 'keyword_argument', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '13', 'type': 'lambda', 'children': ['14', '16']},{'id': '14', 'type': 'lambda_parameters', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '16', 'type': 'tuple', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'R'} | def sort_edge(edges):
return sorted(edges, key=lambda x: (x.L, x.R)) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '25']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'stanc'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13', '16', '19', '22']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'charset'},{'id': '9', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'model_code'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'model_name'},{'id': '15', 'type': 'string', 'children': [], 'value': '"anon_model"'},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'include_paths'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '21', 'type': 'False', 'children': []},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'obfuscate_model_name'},{'id': '24', 'type': 'True', 'children': []},{'id': '25', 'type': 'block', 'children': ['26', '38', '52', '111', '120', '149', '165', '178', '182', '203', '212', '245', '260', '321', '325', '335', '345', '355']},{'id': '26', 'type': 'if_statement', 'children': ['27', '30']},{'id': '27', 'type': 'boolean_operator', 'children': ['28', '29'], 'value': 'and'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'model_code'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'raise_statement', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'concatenated_string', 'children': ['36', '37']},{'id': '36', 'type': 'string', 'children': [], 'value': '"Specify stan model with `file` or `model_code`, "'},{'id': '37', 'type': 'string', 'children': [], 'value': '"not both."'},{'id': '38', 'type': 'if_statement', 'children': ['39', '46']},{'id': '39', 'type': 'boolean_operator', 'children': ['40', '43'], 'value': 'and'},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': 'is'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '42', 'type': 'None', 'children': []},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': 'is'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'model_code'},{'id': '45', 'type': 'None', 'children': []},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'raise_statement', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'string', 'children': [], 'value': '"Model file missing and empty model_code."'},{'id': '52', 'type': 'if_statement', 'children': ['53', '56']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': 'is'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '55', 'type': 'None', 'children': []},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'if_statement', 'children': ['58', '63', '101']},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '60', 'type': 'argument_list', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'try_statement', 'children': ['65', '91']},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'with_statement', 'children': ['67', '82']},{'id': '67', 'type': 'with_clause', 'children': ['68']},{'id': '68', 'type': 'with_item', 'children': ['69']},{'id': '69', 'type': 'as_pattern', 'children': ['70', '80']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'io'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76', '77']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '76', 'type': 'string', 'children': [], 'value': "'rt'"},{'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'charset'},{'id': '80', 'type': 'as_pattern_target', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'model_code'},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '90', 'type': 'argument_list', 'children': []},{'id': '91', 'type': 'except_clause', 'children': ['92']},{'id': '92', 'type': 'block', 'children': ['93', '100']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'critical'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'string', 'children': [], 'value': '"Unable to read file specified by `file`."'},{'id': '100', 'type': 'raise_statement', 'children': []},{'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': 'model_code'},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '110', 'type': 'argument_list', 'children': []},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'model_code_bytes'},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'model_code'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '120', 'type': 'if_statement', 'children': ['121', '124', '137']},{'id': '121', 'type': 'comparison_operator', 'children': ['122', '123'], 'value': 'is'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'include_paths'},{'id': '123', 'type': 'None', 'children': []},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'include_paths'},{'id': '128', 'type': 'list', 'children': ['129'], 'value': "[os.path.abspath('.')]"},{'id': '129', 'type': 'call', 'children': ['130', '135']},{'id': '130', 'type': 'attribute', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'abspath'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '137', 'type': 'elif_clause', 'children': ['138', '143']},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '140', 'type': 'argument_list', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'include_paths'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '143', 'type': 'block', 'children': ['144']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'include_paths'},{'id': '147', 'type': 'list', 'children': ['148'], 'value': '[include_paths]'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'include_paths'},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'include_paths'},{'id': '152', 'type': 'list_comprehension', 'children': ['153', '162']},{'id': '153', 'type': 'call', 'children': ['154', '159']},{'id': '154', 'type': 'attribute', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '159', 'type': 'argument_list', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '161', 'type': 'string', 'children': [], 'value': '""'},{'id': '162', 'type': 'for_in_clause', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'include_paths'},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'include_paths_bytes'},{'id': '168', 'type': 'list_comprehension', 'children': ['169', '175']},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '175', 'type': 'for_in_clause', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'include_paths'},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'allow_undefined'},{'id': '181', 'type': 'False', 'children': []},{'id': '182', 'type': 'if_statement', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'obfuscate_model_name'},{'id': '184', 'type': 'block', 'children': ['185']},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'model_name'},{'id': '188', 'type': '()', 'children': ['189']},{'id': '189', 'type': 'binary_operator', 'children': ['190', '193'], 'value': '+'},{'id': '190', 'type': 'binary_operator', 'children': ['191', '192'], 'value': '+'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'model_name'},{'id': '192', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '193', 'type': 'call', 'children': ['194', '202']},{'id': '194', 'type': 'attribute', 'children': ['195', '201']},{'id': '195', 'type': 'call', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'hashlib'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'md5'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'model_code_bytes'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'hexdigest'},{'id': '202', 'type': 'argument_list', 'children': []},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'assignment', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'model_name_bytes'},{'id': '206', 'type': 'call', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'model_name'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'string', 'children': [], 'value': "'ascii'"},{'id': '212', 'type': 'if_statement', 'children': ['213', '219', '224']},{'id': '213', 'type': 'not_operator', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '216', 'type': 'argument_list', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'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': 'filename_bytes'},{'id': '223', 'type': 'string', 'children': [], 'value': "b'unknown file name'"},{'id': '224', 'type': 'else_clause', 'children': ['225']},{'id': '225', 'type': 'block', 'children': ['226']},{'id': '226', 'type': 'expression_statement', 'children': ['227']},{'id': '227', 'type': 'assignment', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'filename_bytes'},{'id': '229', 'type': 'call', 'children': ['230', '243']},{'id': '230', 'type': 'attribute', 'children': ['231', '242']},{'id': '231', 'type': 'subscript', 'children': ['232', '240']},{'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': 'os'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '238', 'type': 'argument_list', 'children': ['239']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '240', 'type': 'unary_operator', 'children': ['241'], 'value': '-'},{'id': '241', 'type': 'integer', 'children': [], 'value': '1'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '243', 'type': 'argument_list', 'children': ['244']},{'id': '244', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'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', '254']},{'id': '249', 'type': 'attribute', 'children': ['250', '253']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'pystan'},{'id': '252', 'type': 'identifier', 'children': [], 'value': '_api'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'stanc'},{'id': '254', 'type': 'argument_list', 'children': ['255', '256', '257', '258', '259']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'model_code_bytes'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'model_name_bytes'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'allow_undefined'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'filename_bytes'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'include_paths_bytes'},{'id': '260', 'type': 'if_statement', 'children': ['261', '267', '302']},{'id': '261', 'type': 'comparison_operator', 'children': ['262', '265'], 'value': '=='},{'id': '262', 'type': 'subscript', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '264', 'type': 'string', 'children': [], 'value': "'status'"},{'id': '265', 'type': 'unary_operator', 'children': ['266'], 'value': '-'},{'id': '266', 'type': 'integer', 'children': [], 'value': '1'},{'id': '267', 'type': 'block', 'children': ['268', '274', '287', '297']},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'assignment', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '271', 'type': 'subscript', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '273', 'type': 'string', 'children': [], 'value': "'msg'"},{'id': '274', 'type': 'if_statement', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'PY2'},{'id': '276', 'type': 'block', 'children': ['277']},{'id': '277', 'type': 'expression_statement', 'children': ['278']},{'id': '278', 'type': 'assignment', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '280', 'type': 'call', 'children': ['281', '284']},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '284', 'type': 'argument_list', 'children': ['285', '286']},{'id': '285', 'type': 'string', 'children': [], 'value': "'ascii'"},{'id': '286', 'type': 'string', 'children': [], 'value': "'replace'"},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'assignment', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'error_msg'},{'id': '290', 'type': 'call', 'children': ['291', '294']},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'string', 'children': [], 'value': '"Failed to parse Stan model \'{}\'. Error message:\\n{}"'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '294', 'type': 'argument_list', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'model_name'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '297', 'type': 'raise_statement', 'children': ['298']},{'id': '298', 'type': 'call', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '300', 'type': 'argument_list', 'children': ['301']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'error_msg'},{'id': '302', 'type': 'elif_clause', 'children': ['303', '308']},{'id': '303', 'type': 'comparison_operator', 'children': ['304', '307'], 'value': '=='},{'id': '304', 'type': 'subscript', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '306', 'type': 'string', 'children': [], 'value': "'status'"},{'id': '307', 'type': 'integer', 'children': [], 'value': '0'},{'id': '308', 'type': 'block', 'children': ['309']},{'id': '309', 'type': 'expression_statement', 'children': ['310']},{'id': '310', 'type': 'call', 'children': ['311', '314']},{'id': '311', 'type': 'attribute', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '314', 'type': 'argument_list', 'children': ['315']},{'id': '315', 'type': 'call', 'children': ['316', '319']},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'string', 'children': [], 'value': '"Successfully parsed Stan model \'{}\'."'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '319', 'type': 'argument_list', 'children': ['320']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'model_name'},{'id': '321', 'type': 'delete_statement', 'children': ['322']},{'id': '322', 'type': 'subscript', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '324', 'type': 'string', 'children': [], 'value': "'msg'"},{'id': '325', 'type': 'expression_statement', 'children': ['326']},{'id': '326', 'type': 'call', 'children': ['327', '330']},{'id': '327', 'type': 'attribute', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '330', 'type': 'argument_list', 'children': ['331']},{'id': '331', 'type': 'dictionary', 'children': ['332']},{'id': '332', 'type': 'pair', 'children': ['333', '334']},{'id': '333', 'type': 'string', 'children': [], 'value': "'model_name'"},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'model_name'},{'id': '335', 'type': 'expression_statement', 'children': ['336']},{'id': '336', 'type': 'call', 'children': ['337', '340']},{'id': '337', 'type': 'attribute', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '340', 'type': 'argument_list', 'children': ['341']},{'id': '341', 'type': 'dictionary', 'children': ['342']},{'id': '342', 'type': 'pair', 'children': ['343', '344']},{'id': '343', 'type': 'string', 'children': [], 'value': "'model_code'"},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'model_code'},{'id': '345', 'type': 'expression_statement', 'children': ['346']},{'id': '346', 'type': 'call', 'children': ['347', '350']},{'id': '347', 'type': 'attribute', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '350', 'type': 'argument_list', 'children': ['351']},{'id': '351', 'type': 'dictionary', 'children': ['352']},{'id': '352', 'type': 'pair', 'children': ['353', '354']},{'id': '353', 'type': 'string', 'children': [], 'value': "'include_paths'"},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'include_paths'},{'id': '355', 'type': 'return_statement', 'children': ['356']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'result'} | def stanc(file=None, charset='utf-8', model_code=None, model_name="anon_model",
include_paths=None, verbose=False, obfuscate_model_name=True):
if file and model_code:
raise ValueError("Specify stan model with `file` or `model_code`, "
"not both.")
if file is None and model_code is None:
raise ValueError("Model file missing and empty model_code.")
if file is not None:
if isinstance(file, string_types):
try:
with io.open(file, 'rt', encoding=charset) as f:
model_code = f.read()
except:
logger.critical("Unable to read file specified by `file`.")
raise
else:
model_code = file.read()
model_code_bytes = model_code.encode('utf-8')
if include_paths is None:
include_paths = [os.path.abspath('.')]
elif isinstance(include_paths, string_types):
include_paths = [include_paths]
include_paths = [os.path.join(path, "") for path in include_paths]
include_paths_bytes = [path.encode('utf-8') for path in include_paths]
allow_undefined = False
if obfuscate_model_name:
model_name = (
model_name + '_' +
hashlib.md5(model_code_bytes).hexdigest())
model_name_bytes = model_name.encode('ascii')
if not isinstance(file, string_types):
filename_bytes = b'unknown file name'
else:
filename_bytes = os.path.split(file)[-1].encode('utf-8')
result = pystan._api.stanc(model_code_bytes, model_name_bytes,
allow_undefined, filename_bytes,
include_paths_bytes,
)
if result['status'] == -1:
msg = result['msg']
if PY2:
msg = msg.encode('ascii', 'replace')
error_msg = "Failed to parse Stan model '{}'. Error message:\n{}".format(model_name, msg)
raise ValueError(error_msg)
elif result['status'] == 0:
logger.debug("Successfully parsed Stan model '{}'.".format(model_name))
del result['msg']
result.update({'model_name': model_name})
result.update({'model_code': model_code})
result.update({'include_paths' : include_paths})
return result |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'suggestion_list'},{'id': '3', 'type': 'parameters', 'children': ['4', '8']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'input_'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '8', 'type': 'typed_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '10', 'type': 'type', 'children': ['11']},{'id': '11', 'type': 'generic_type', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'Collection'},{'id': '13', 'type': 'type_parameter', 'children': ['14']},{'id': '14', 'type': 'type', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '16', 'type': 'block', 'children': ['17', '21', '30', '67']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'options_by_distance'},{'id': '20', 'type': 'dictionary', 'children': []},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'input_threshold'},{'id': '24', 'type': 'binary_operator', 'children': ['25', '29'], 'value': '//'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'input_'},{'id': '29', 'type': 'integer', 'children': [], 'value': '2'},{'id': '30', 'type': 'for_statement', 'children': ['31', '32', '33']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'option'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '33', 'type': 'block', 'children': ['34', '42', '56']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'lexical_distance'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'input_'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'option'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49', '55']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'input_threshold'},{'id': '49', 'type': 'binary_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': 'option'},{'id': '54', 'type': 'integer', 'children': [], 'value': '2'},{'id': '55', 'type': 'integer', 'children': [], 'value': '1'},{'id': '56', 'type': 'if_statement', 'children': ['57', '60']},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': '<='},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '66']},{'id': '63', 'type': 'subscript', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'options_by_distance'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'option'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '67', 'type': 'return_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '70', 'type': 'argument_list', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'options_by_distance'},{'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'options_by_distance'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'get'} | def suggestion_list(input_: str, options: Collection[str]):
options_by_distance = {}
input_threshold = len(input_) // 2
for option in options:
distance = lexical_distance(input_, option)
threshold = max(input_threshold, len(option) // 2, 1)
if distance <= threshold:
options_by_distance[option] = distance
return sorted(options_by_distance, key=options_by_distance.get) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'lexical_distance'},{'id': '3', 'type': 'parameters', 'children': ['4', '8']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'a_str'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '8', 'type': 'typed_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'b_str'},{'id': '10', 'type': 'type', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '12', 'type': 'type', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '14', 'type': 'block', 'children': ['15', '22', '38', '52', '59', '74', '97', '232']},{'id': '15', 'type': 'if_statement', 'children': ['16', '19']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': '=='},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'a_str'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'b_str'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'return_statement', 'children': ['21']},{'id': '21', 'type': 'integer', 'children': [], 'value': '0'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '27']},{'id': '24', 'type': 'pattern_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '27', 'type': 'expression_list', 'children': ['28', '33']},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'a_str'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'b_str'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '37', 'type': 'argument_list', 'children': []},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '43']},{'id': '40', 'type': 'pattern_list', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'a_len'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'b_len'},{'id': '43', 'type': 'expression_list', 'children': ['44', '48']},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '52', 'type': 'if_statement', 'children': ['53', '56']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': '=='},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'return_statement', 'children': ['58']},{'id': '58', 'type': 'integer', 'children': [], 'value': '1'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '62', 'type': 'list', 'children': ['63'], 'value': '[[j for j in range(0, b_len + 1)]]'},{'id': '63', 'type': 'list_comprehension', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '65', 'type': 'for_in_clause', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'integer', 'children': [], 'value': '0'},{'id': '71', 'type': 'binary_operator', 'children': ['72', '73'], 'value': '+'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'b_len'},{'id': '73', 'type': 'integer', 'children': [], 'value': '1'},{'id': '74', 'type': 'for_statement', 'children': ['75', '76', '83']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80']},{'id': '79', 'type': 'integer', 'children': [], 'value': '1'},{'id': '80', 'type': 'binary_operator', 'children': ['81', '82'], 'value': '+'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'a_len'},{'id': '82', 'type': 'integer', 'children': [], 'value': '1'},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'binary_operator', 'children': ['91', '93'], 'value': '+'},{'id': '91', 'type': 'list', 'children': ['92'], 'value': '[i]'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '93', 'type': 'binary_operator', 'children': ['94', '96'], 'value': '*'},{'id': '94', 'type': 'list', 'children': ['95'], 'value': '[0]'},{'id': '95', 'type': 'integer', 'children': [], 'value': '0'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'b_len'},{'id': '97', 'type': 'for_statement', 'children': ['98', '99', '106']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '101', 'type': 'argument_list', 'children': ['102', '103']},{'id': '102', 'type': 'integer', 'children': [], 'value': '1'},{'id': '103', 'type': 'binary_operator', 'children': ['104', '105'], 'value': '+'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'a_len'},{'id': '105', 'type': 'integer', 'children': [], 'value': '1'},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'for_statement', 'children': ['108', '109', '116']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '111', 'type': 'argument_list', 'children': ['112', '113']},{'id': '112', 'type': 'integer', 'children': [], 'value': '1'},{'id': '113', 'type': 'binary_operator', 'children': ['114', '115'], 'value': '+'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'b_len'},{'id': '115', 'type': 'integer', 'children': [], 'value': '1'},{'id': '116', 'type': 'block', 'children': ['117', '134', '173']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'cost'},{'id': '120', 'type': 'conditional_expression', 'children': ['121', '122', '133'], 'value': 'if'},{'id': '121', 'type': 'integer', 'children': [], 'value': '0'},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '128'], 'value': '=='},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '125', 'type': 'binary_operator', 'children': ['126', '127'], 'value': '-'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '127', 'type': 'integer', 'children': [], 'value': '1'},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '130', 'type': 'binary_operator', 'children': ['131', '132'], 'value': '-'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '132', 'type': 'integer', 'children': [], 'value': '1'},{'id': '133', 'type': 'integer', 'children': [], 'value': '1'},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '141']},{'id': '136', 'type': 'subscript', 'children': ['137', '140']},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '143', 'type': 'argument_list', 'children': ['144', '153', '162']},{'id': '144', 'type': 'binary_operator', 'children': ['145', '152'], 'value': '+'},{'id': '145', 'type': 'subscript', 'children': ['146', '151']},{'id': '146', 'type': 'subscript', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '148', 'type': 'binary_operator', 'children': ['149', '150'], 'value': '-'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '150', 'type': 'integer', 'children': [], 'value': '1'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '152', 'type': 'integer', 'children': [], 'value': '1'},{'id': '153', 'type': 'binary_operator', 'children': ['154', '161'], 'value': '+'},{'id': '154', 'type': 'subscript', 'children': ['155', '158']},{'id': '155', 'type': 'subscript', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '158', 'type': 'binary_operator', 'children': ['159', '160'], 'value': '-'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '160', 'type': 'integer', 'children': [], 'value': '1'},{'id': '161', 'type': 'integer', 'children': [], 'value': '1'},{'id': '162', 'type': 'binary_operator', 'children': ['163', '172'], 'value': '+'},{'id': '163', 'type': 'subscript', 'children': ['164', '169']},{'id': '164', 'type': 'subscript', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '166', 'type': 'binary_operator', 'children': ['167', '168'], 'value': '-'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '168', 'type': 'integer', 'children': [], 'value': '1'},{'id': '169', 'type': 'binary_operator', 'children': ['170', '171'], 'value': '-'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '171', 'type': 'integer', 'children': [], 'value': '1'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'cost'},{'id': '173', 'type': 'if_statement', 'children': ['174', '205']},{'id': '174', 'type': 'boolean_operator', 'children': ['175', '194'], 'value': 'and'},{'id': '175', 'type': 'boolean_operator', 'children': ['176', '183'], 'value': 'and'},{'id': '176', 'type': 'boolean_operator', 'children': ['177', '180'], 'value': 'and'},{'id': '177', 'type': 'comparison_operator', 'children': ['178', '179'], 'value': '>'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '179', 'type': 'integer', 'children': [], 'value': '1'},{'id': '180', 'type': 'comparison_operator', 'children': ['181', '182'], 'value': '>'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '182', 'type': 'integer', 'children': [], 'value': '1'},{'id': '183', 'type': 'comparison_operator', 'children': ['184', '189'], 'value': '=='},{'id': '184', 'type': 'subscript', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '186', 'type': 'binary_operator', 'children': ['187', '188'], 'value': '-'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '188', 'type': 'integer', 'children': [], 'value': '1'},{'id': '189', 'type': 'subscript', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '191', 'type': 'binary_operator', 'children': ['192', '193'], 'value': '-'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '193', 'type': 'integer', 'children': [], 'value': '2'},{'id': '194', 'type': 'comparison_operator', 'children': ['195', '200'], 'value': '=='},{'id': '195', 'type': 'subscript', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '197', 'type': 'binary_operator', 'children': ['198', '199'], 'value': '-'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '199', 'type': 'integer', 'children': [], 'value': '2'},{'id': '200', 'type': 'subscript', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '202', 'type': 'binary_operator', 'children': ['203', '204'], 'value': '-'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '204', 'type': 'integer', 'children': [], 'value': '1'},{'id': '205', 'type': 'block', 'children': ['206']},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '213']},{'id': '208', 'type': 'subscript', 'children': ['209', '212']},{'id': '209', 'type': 'subscript', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '213', 'type': 'call', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '215', 'type': 'argument_list', 'children': ['216', '221']},{'id': '216', 'type': 'subscript', 'children': ['217', '220']},{'id': '217', 'type': 'subscript', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '221', 'type': 'binary_operator', 'children': ['222', '231'], 'value': '+'},{'id': '222', 'type': 'subscript', 'children': ['223', '228']},{'id': '223', 'type': 'subscript', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '225', 'type': 'binary_operator', 'children': ['226', '227'], 'value': '-'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '227', 'type': 'integer', 'children': [], 'value': '2'},{'id': '228', 'type': 'binary_operator', 'children': ['229', '230'], 'value': '-'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '230', 'type': 'integer', 'children': [], 'value': '2'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'cost'},{'id': '232', 'type': 'return_statement', 'children': ['233']},{'id': '233', 'type': 'subscript', 'children': ['234', '237']},{'id': '234', 'type': 'subscript', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'a_len'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'b_len'} | def lexical_distance(a_str: str, b_str: str) -> int:
if a_str == b_str:
return 0
a, b = a_str.lower(), b_str.lower()
a_len, b_len = len(a), len(b)
if a == b:
return 1
d = [[j for j in range(0, b_len + 1)]]
for i in range(1, a_len + 1):
d.append([i] + [0] * b_len)
for i in range(1, a_len + 1):
for j in range(1, b_len + 1):
cost = 0 if a[i - 1] == b[j - 1] else 1
d[i][j] = min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost)
if i > 1 and j > 1 and a[i - 1] == b[j - 2] and a[i - 2] == b[j - 1]:
d[i][j] = min(d[i][j], d[i - 2][j - 2] + cost)
return d[a_len][b_len] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16', '22']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_suggested_type_names'},{'id': '3', 'type': 'parameters', 'children': ['4', '8', '12']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'GraphQLSchema'},{'id': '8', 'type': 'typed_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '10', 'type': 'type', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'GraphQLOutputType'},{'id': '12', 'type': 'typed_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '14', 'type': 'type', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '16', 'type': 'type', 'children': ['17']},{'id': '17', 'type': 'generic_type', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'List'},{'id': '19', 'type': 'type_parameter', 'children': ['20']},{'id': '20', 'type': 'type', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '22', 'type': 'block', 'children': ['23', '124']},{'id': '23', 'type': 'if_statement', 'children': ['24', '28']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'is_abstract_type'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '28', 'type': 'block', 'children': ['29', '37', '41', '56', '104', '120']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'cast'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'GraphQLAbstractType'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'suggested_object_types'},{'id': '40', 'type': 'list', 'children': [], 'value': '[]'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44', '52']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'interface_usage_count'},{'id': '44', 'type': 'type', 'children': ['45']},{'id': '45', 'type': 'generic_type', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'Dict'},{'id': '47', 'type': 'type_parameter', 'children': ['48', '50']},{'id': '48', 'type': 'type', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '50', 'type': 'type', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '56', 'type': 'for_statement', 'children': ['57', '58', '64']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'possible_type'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'get_possible_types'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '64', 'type': 'block', 'children': ['65', '73', '82']},{'id': '65', 'type': 'if_statement', 'children': ['66', '71']},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': 'not'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'possible_type'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'continue_statement', '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': 'suggested_object_types'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'possible_type'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '82', 'type': 'for_statement', 'children': ['83', '84', '87']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'possible_interface'},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'possible_type'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'interfaces'},{'id': '87', 'type': 'block', 'children': ['88', '96']},{'id': '88', 'type': 'if_statement', 'children': ['89', '94']},{'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': 'not'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'possible_interface'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'continue_statement', 'children': []},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'augmented_assignment', 'children': ['98', '103'], 'value': '+='},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'interface_usage_count'},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'possible_interface'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '103', 'type': 'integer', 'children': [], 'value': '1'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'suggested_interface_types'},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '109', 'type': 'argument_list', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'interface_usage_count'},{'id': '111', 'type': 'keyword_argument', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '113', 'type': 'lambda', 'children': ['114', '116']},{'id': '114', 'type': 'lambda_parameters', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '116', 'type': 'unary_operator', 'children': ['117'], 'value': '-'},{'id': '117', 'type': 'subscript', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'interface_usage_count'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '120', 'type': 'return_statement', 'children': ['121']},{'id': '121', 'type': 'binary_operator', 'children': ['122', '123'], 'value': '+'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'suggested_interface_types'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'suggested_object_types'},{'id': '124', 'type': 'return_statement', 'children': ['125']},{'id': '125', 'type': 'list', 'children': [], 'value': '[]'} | def get_suggested_type_names(
schema: GraphQLSchema, type_: GraphQLOutputType, field_name: str
) -> List[str]:
if is_abstract_type(type_):
type_ = cast(GraphQLAbstractType, type_)
suggested_object_types = []
interface_usage_count: Dict[str, int] = defaultdict(int)
for possible_type in schema.get_possible_types(type_):
if field_name not in possible_type.fields:
continue
suggested_object_types.append(possible_type.name)
for possible_interface in possible_type.interfaces:
if field_name not in possible_interface.fields:
continue
interface_usage_count[possible_interface.name] += 1
suggested_interface_types = sorted(
interface_usage_count, key=lambda k: -interface_usage_count[k]
)
return suggested_interface_types + suggested_object_types
return [] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'instances_get'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'plugins'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'url_file_input'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '8', 'type': 'block', 'children': ['9', '15', '22', '57', '88']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'instances'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'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': 'preferred_order'},{'id': '18', 'type': 'list', 'children': ['19', '20', '21'], 'value': "['wordpress', 'joomla', 'drupal']"},{'id': '19', 'type': 'string', 'children': [], 'value': "'wordpress'"},{'id': '20', 'type': 'string', 'children': [], 'value': "'joomla'"},{'id': '21', 'type': 'string', 'children': [], 'value': "'drupal'"},{'id': '22', 'type': 'for_statement', 'children': ['23', '24', '25']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'cms_name'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'preferred_order'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'for_statement', 'children': ['27', '28', '29']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'plugin'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'plugins'},{'id': '29', 'type': 'block', 'children': ['30', '40']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'plugin_name'},{'id': '33', 'type': 'call', 'children': ['34', '39']},{'id': '34', 'type': 'attribute', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'plugin'},{'id': '37', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'if_statement', 'children': ['41', '44']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': '=='},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'cms_name'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'plugin_name'},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '50']},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'instances'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'plugin_name'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'instance_get'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54', '55', '56']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'plugin'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'url_file_input'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '57', 'type': 'for_statement', 'children': ['58', '59', '60']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'plugin'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'plugins'},{'id': '60', 'type': 'block', 'children': ['61', '71']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'plugin_name'},{'id': '64', 'type': 'call', 'children': ['65', '70']},{'id': '65', 'type': 'attribute', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'plugin'},{'id': '68', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '70', 'type': 'argument_list', 'children': []},{'id': '71', 'type': 'if_statement', 'children': ['72', '75']},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': 'not'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'plugin_name'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'preferred_order'},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '81']},{'id': '78', 'type': 'subscript', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'instances'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'plugin_name'},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'instance_get'},{'id': '83', 'type': 'argument_list', 'children': ['84', '85', '86', '87']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'plugin'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'url_file_input'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '88', 'type': 'return_statement', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'instances'} | def instances_get(opts, plugins, url_file_input, out):
instances = OrderedDict()
preferred_order = ['wordpress', 'joomla', 'drupal']
for cms_name in preferred_order:
for plugin in plugins:
plugin_name = plugin.__name__.lower()
if cms_name == plugin_name:
instances[plugin_name] = instance_get(plugin, opts,
url_file_input, out)
for plugin in plugins:
plugin_name = plugin.__name__.lower()
if plugin_name not in preferred_order:
instances[plugin_name] = instance_get(plugin, opts,
url_file_input, out)
return instances |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_signed_headers'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '5', 'type': 'block', 'children': ['6', '10', '29']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'signed_headers'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'for_statement', 'children': ['11', '12', '13']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'signed_headers'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '28']},{'id': '21', 'type': 'attribute', 'children': ['22', '27']},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '28', 'type': 'argument_list', 'children': []},{'id': '29', 'type': 'return_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'signed_headers'} | def get_signed_headers(headers):
signed_headers = []
for header in headers:
signed_headers.append(header.lower().strip())
return sorted(signed_headers) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_from_names_to_locals'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '6', 'type': 'block', 'children': ['7', '16', '30']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': '_key_func'},{'id': '10', 'type': 'lambda', 'children': ['11', '13']},{'id': '11', 'type': 'lambda_parameters', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'fromlineno'},{'id': '16', 'type': 'function_definition', 'children': ['17', '18', '20']},{'id': '17', 'type': 'function_name', 'children': [], 'value': 'sort_locals'},{'id': '18', 'type': 'parameters', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'my_list'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'my_list'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_key_func'},{'id': '30', 'type': 'for_statement', 'children': ['31', '34', '37']},{'id': '31', 'type': 'tuple_pattern', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'asname'},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'if_statement', 'children': ['39', '42', '92']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': '=='},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '41', 'type': 'string', 'children': [], 'value': '"*"'},{'id': '42', 'type': 'block', 'children': ['43', '59']},{'id': '43', 'type': 'try_statement', 'children': ['44', '53']},{'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': 'imported'},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'do_import_module'},{'id': '52', 'type': 'argument_list', 'children': []},{'id': '53', 'type': 'except_clause', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'AstroidBuildingError'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'continue_statement', 'children': []},{'id': '59', 'type': 'for_statement', 'children': ['60', '61', '66']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'imported'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'public_names'},{'id': '65', 'type': 'argument_list', 'children': []},{'id': '66', 'type': 'block', 'children': ['67', '77']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '74']},{'id': '69', 'type': 'attribute', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'set_local'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'sort_locals'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'subscript', 'children': ['82', '91']},{'id': '82', 'type': 'attribute', 'children': ['83', '90']},{'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': 'node'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'scope'},{'id': '89', 'type': 'argument_list', 'children': []},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '92', 'type': 'else_clause', 'children': ['93']},{'id': '93', 'type': 'block', 'children': ['94', '106']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '101']},{'id': '96', 'type': 'attribute', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'set_local'},{'id': '101', 'type': 'argument_list', 'children': ['102', '105']},{'id': '102', 'type': 'boolean_operator', 'children': ['103', '104'], 'value': 'or'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'asname'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'sort_locals'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'subscript', 'children': ['111', '120']},{'id': '111', 'type': 'attribute', 'children': ['112', '119']},{'id': '112', 'type': 'call', 'children': ['113', '118']},{'id': '113', 'type': 'attribute', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'scope'},{'id': '118', 'type': 'argument_list', 'children': []},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '120', 'type': 'boolean_operator', 'children': ['121', '122'], 'value': 'or'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'asname'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'name'} | def add_from_names_to_locals(self, node):
_key_func = lambda node: node.fromlineno
def sort_locals(my_list):
my_list.sort(key=_key_func)
for (name, asname) in node.names:
if name == "*":
try:
imported = node.do_import_module()
except exceptions.AstroidBuildingError:
continue
for name in imported.public_names():
node.parent.set_local(name, node)
sort_locals(node.parent.scope().locals[name])
else:
node.parent.set_local(asname or name, node)
sort_locals(node.parent.scope().locals[asname or name]) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'nearest'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '6', 'type': 'block', 'children': ['7', '15', '21', '27', '72']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'myroot'},{'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': 'root'},{'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': 'mylineno'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'fromlineno'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'nearest'},{'id': '24', 'type': 'expression_list', 'children': ['25', '26']},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'integer', 'children': [], 'value': '0'},{'id': '27', 'type': 'for_statement', 'children': ['28', '29', '30']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '30', 'type': 'block', 'children': ['31', '45', '51', '59']},{'id': '31', 'type': 'assert_statement', 'children': ['32', '39']},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '38'], 'value': 'is'},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '37', 'type': 'argument_list', 'children': []},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'myroot'},{'id': '39', 'type': '()', 'children': ['40']},{'id': '40', 'type': 'binary_operator', 'children': ['41', '42'], 'value': '%'},{'id': '41', 'type': 'string', 'children': [], 'value': '"nodes %s and %s are not from the same module"'},{'id': '42', 'type': 'tuple', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'lineno'},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'fromlineno'},{'id': '51', 'type': 'if_statement', 'children': ['52', '57']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '56'], 'value': '>'},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'fromlineno'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'mylineno'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'break_statement', 'children': []},{'id': '59', 'type': 'if_statement', 'children': ['60', '65']},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': '>'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'lineno'},{'id': '62', 'type': 'subscript', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'nearest'},{'id': '64', 'type': 'integer', 'children': [], 'value': '1'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'nearest'},{'id': '69', 'type': 'expression_list', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'lineno'},{'id': '72', 'type': 'return_statement', 'children': ['73']},{'id': '73', 'type': 'subscript', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'nearest'},{'id': '75', 'type': 'integer', 'children': [], 'value': '0'} | def nearest(self, nodes):
myroot = self.root()
mylineno = self.fromlineno
nearest = None, 0
for node in nodes:
assert node.root() is myroot, (
"nodes %s and %s are not from the same module" % (self, node)
)
lineno = node.fromlineno
if node.fromlineno > mylineno:
break
if lineno > nearest[1]:
nearest = node, lineno
return nearest[0] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'object_type'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '31', '46']},{'id': '9', 'type': 'try_statement', 'children': ['10', '22']},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'types'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_object_type'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '22', 'type': 'except_clause', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'InferenceError'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'return_statement', 'children': ['28']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'util'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'Uninferable'},{'id': '31', 'type': 'if_statement', 'children': ['32', '41']},{'id': '32', 'type': 'boolean_operator', 'children': ['33', '39'], 'value': 'or'},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '38'], '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': 'identifier', 'children': [], 'value': 'types'},{'id': '38', 'type': 'integer', 'children': [], 'value': '1'},{'id': '39', 'type': 'not_operator', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'types'},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'return_statement', 'children': ['43']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'util'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'Uninferable'},{'id': '46', 'type': 'return_statement', 'children': ['47']},{'id': '47', 'type': 'subscript', 'children': ['48', '52']},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'types'},{'id': '52', 'type': 'integer', 'children': [], 'value': '0'} | def object_type(node, context=None):
try:
types = set(_object_type(node, context))
except exceptions.InferenceError:
return util.Uninferable
if len(types) > 1 or not types:
return util.Uninferable
return list(types)[0] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_deffacts'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'return_statement', 'children': ['7']},{'id': '7', 'type': 'call', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '9', 'type': 'argument_list', 'children': ['10', '16']},{'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': '_get_by_type'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'DefFacts'},{'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '18', 'type': 'lambda', 'children': ['19', '21']},{'id': '19', 'type': 'lambda_parameters', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'order'} | def get_deffacts(self):
return sorted(self._get_by_type(DefFacts), key=lambda d: d.order) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'json_dumps'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'return_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '33']},{'id': '9', 'type': 'attribute', 'children': ['10', '32']},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '14', 'type': 'argument_list', 'children': ['15', '16', '21', '24', '29']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'separators'},{'id': '18', 'type': 'tuple', 'children': ['19', '20']},{'id': '19', 'type': 'string', 'children': [], 'value': "','"},{'id': '20', 'type': 'string', 'children': [], 'value': "':'"},{'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '23', 'type': 'True', 'children': []},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'json_encoder'},{'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'ensure_ascii'},{'id': '31', 'type': 'False', 'children': []},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'string', 'children': [], 'value': "'utf8'"} | def json_dumps(self, data):
return json.dumps(
data,
separators=(',', ':'),
sort_keys=True,
cls=self.json_encoder,
ensure_ascii=False
).encode('utf8') |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_waveform_generator'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'variable_params'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'recalibration'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'gates'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'dictionary_splat_pattern', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'static_params'},{'id': '14', 'type': 'block', 'children': ['15', '31', '40', '44', '106', '145']},{'id': '15', 'type': 'try_statement', 'children': ['16', '23']},{'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': 'approximant'},{'id': '20', 'type': 'subscript', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'static_params'},{'id': '22', 'type': 'string', 'children': [], 'value': "'approximant'"},{'id': '23', 'type': 'except_clause', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'raise_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'string', 'children': [], 'value': '"no approximant provided in the static args"'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'generator_function'},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'generator'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'select_waveform_generator'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'approximant'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'delta_f'},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': 'for_statement', 'children': ['45', '46', '51']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '50', 'type': 'argument_list', 'children': []},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'if_statement', 'children': ['53', '56', '75']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': 'is'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'delta_f'},{'id': '55', 'type': 'None', 'children': []},{'id': '56', 'type': 'block', 'children': ['57', '63', '69']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'delta_f'},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'delta_f'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'delta_t'},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'delta_t'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '75', 'type': 'else_clause', 'children': ['76']},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'if_statement', 'children': ['78', '98']},{'id': '78', 'type': 'not_operator', 'children': ['79']},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'list', 'children': ['83', '88', '93'], 'value': '[d.delta_f == delta_f, d.delta_t == delta_t,\n d.start_time == start_time]'},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '87'], 'value': '=='},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'delta_f'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'delta_f'},{'id': '88', 'type': 'comparison_operator', 'children': ['89', '92'], 'value': '=='},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'delta_t'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'delta_t'},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '97'], 'value': '=='},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'raise_statement', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'concatenated_string', 'children': ['104', '105']},{'id': '104', 'type': 'string', 'children': [], 'value': '"data must all have the same delta_t, "'},{'id': '105', 'type': 'string', 'children': [], 'value': '"delta_f, and start_time"'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'waveform_generator'},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'generator'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'FDomainDetFrameGenerator'},{'id': '113', 'type': 'argument_list', 'children': ['114', '115', '118', '121', '131', '134', '137', '140', '143']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'generator_function'},{'id': '115', 'type': 'keyword_argument', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'epoch'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'variable_args'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'variable_params'},{'id': '121', 'type': 'keyword_argument', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'detectors'},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '130', 'type': 'argument_list', 'children': []},{'id': '131', 'type': 'keyword_argument', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'delta_f'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'delta_f'},{'id': '134', 'type': 'keyword_argument', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'delta_t'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'delta_t'},{'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'recalib'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'recalibration'},{'id': '140', 'type': 'keyword_argument', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'gates'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'gates'},{'id': '143', 'type': 'dictionary_splat', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'static_params'},{'id': '145', 'type': 'return_statement', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'waveform_generator'} | def create_waveform_generator(variable_params, data,
recalibration=None, gates=None,
**static_params):
try:
approximant = static_params['approximant']
except KeyError:
raise ValueError("no approximant provided in the static args")
generator_function = generator.select_waveform_generator(approximant)
delta_f = None
for d in data.values():
if delta_f is None:
delta_f = d.delta_f
delta_t = d.delta_t
start_time = d.start_time
else:
if not all([d.delta_f == delta_f, d.delta_t == delta_t,
d.start_time == start_time]):
raise ValueError("data must all have the same delta_t, "
"delta_f, and start_time")
waveform_generator = generator.FDomainDetFrameGenerator(
generator_function, epoch=start_time,
variable_args=variable_params, detectors=list(data.keys()),
delta_f=delta_f, delta_t=delta_t,
recalib=recalibration, gates=gates,
**static_params)
return waveform_generator |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'rst_dict_table'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'dict_'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'key_format'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'val_format'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '16', 'type': 'True', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '32', '40', '48', '59', '70', '101', '115', '139', '144', '160', '168', '178', '207', '214']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '23']},{'id': '20', 'type': 'pattern_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'list_splat', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'dict_'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'key_format'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'val_format'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'nckey'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'ncval'},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '67', 'type': 'argument_list', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '70', 'type': 'if_statement', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '72', 'type': 'block', 'children': ['73', '79', '90']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '78']},{'id': '75', 'type': 'pattern_list', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'khead'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'vhead'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'nckey'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '84', 'type': 'argument_list', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'nckey'},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'khead'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'ncval'},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '95', 'type': 'argument_list', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'ncval'},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'vhead'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'divider'},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'string', 'children': [], 'value': '"{} {}"'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '108', 'type': 'argument_list', 'children': ['109', '112']},{'id': '109', 'type': 'binary_operator', 'children': ['110', '111'], 'value': '*'},{'id': '110', 'type': 'string', 'children': [], 'value': "'='"},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'nckey'},{'id': '112', 'type': 'binary_operator', 'children': ['113', '114'], 'value': '*'},{'id': '113', 'type': 'string', 'children': [], 'value': "'='"},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'ncval'},{'id': '115', 'type': 'function_definition', 'children': ['116', '117', '120']},{'id': '116', 'type': 'function_name', 'children': [], 'value': 'row'},{'id': '117', 'type': 'parameters', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '120', 'type': 'block', 'children': ['121', '131']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'string', 'children': [], 'value': "'{{0:{0}s}} {{1}}'"},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '128', 'type': 'argument_list', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'nckey'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'ncval'},{'id': '131', 'type': 'return_statement', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '136', 'type': 'argument_list', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '142', 'type': 'list', 'children': ['143'], 'value': '[divider]'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'divider'},{'id': '144', 'type': 'if_statement', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'tuple', 'children': ['154', '159']},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'list_splat', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'divider'},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '165', 'type': 'argument_list', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '168', 'type': 'if_statement', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'sort'},{'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': 'params'},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '178', 'type': 'for_statement', 'children': ['179', '182', '183']},{'id': '179', 'type': 'pattern_list', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '183', 'type': 'block', 'children': ['184', '194']},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'assignment', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'string', 'children': [], 'value': "'{{0:{0}s}} {{1}}'"},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'nckey'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'ncval'},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'call', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'call', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '204', 'type': 'argument_list', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'call', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '212', 'type': 'argument_list', 'children': ['213']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'divider'},{'id': '214', 'type': 'return_statement', 'children': ['215']},{'id': '215', 'type': 'call', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'lines'} | def rst_dict_table(dict_, key_format=str, val_format=str, header=None,
sort=True):
keys, values = zip(*dict_.items())
keys = map(key_format, keys)
values = map(val_format, values)
nckey = max(map(len, keys))
ncval = max(map(len, values))
if header:
khead, vhead = header
nckey = max(nckey, len(khead))
ncval = max(ncval, len(vhead))
divider = "{} {}".format('='*nckey, '='*ncval)
def row(key, val):
fmt = '{{0:{0}s}} {{1}}'.format(nckey, ncval)
return fmt.format(key, val)
lines = [divider]
if header:
lines.extend((row(*header), divider))
params = zip(keys, values)
if sort:
params = sorted(params)
for key, val in params:
fmt = '{{0:{0}s}} {{1}}'.format(nckey, ncval)
lines.append(fmt.format(key, val))
lines.append(divider)
return '\n'.join(lines) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'read_transforms_from_config'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cp'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'section'},{'id': '7', 'type': 'string', 'children': [], 'value': '"transforms"'},{'id': '8', 'type': 'block', 'children': ['9', '13', '53']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'trans'},{'id': '12', 'type': 'list', 'children': [], 'value': '[]'},{'id': '13', 'type': 'for_statement', 'children': ['14', '15', '21']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'subsection'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'cp'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'get_subsections'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'section'},{'id': '21', 'type': 'block', 'children': ['22', '33', '46']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'cp'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'get_opt_tag'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31', '32']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'section'},{'id': '31', 'type': 'string', 'children': [], 'value': '"name"'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'subsection'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '36', 'type': 'call', 'children': ['37', '42']},{'id': '37', 'type': 'attribute', 'children': ['38', '41']},{'id': '38', 'type': 'subscript', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'transforms'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'from_config'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44', '45']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'cp'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'section'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'subsection'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'trans'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '53', 'type': 'return_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'order_transforms'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'trans'} | def read_transforms_from_config(cp, section="transforms"):
trans = []
for subsection in cp.get_subsections(section):
name = cp.get_opt_tag(section, "name", subsection)
t = transforms[name].from_config(cp, section, subsection)
trans.append(t)
return order_transforms(trans) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'samples_from_cli'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'dictionary_splat_pattern', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '11', 'type': 'block', 'children': ['12', '40', '50', '60', '72']},{'id': '12', 'type': 'if_statement', 'children': ['13', '22', '29']},{'id': '13', 'type': 'boolean_operator', 'children': ['14', '17'], 'value': 'and'},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'is'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '21'], 'value': 'is'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'variable_args'},{'id': '29', 'type': 'elif_clause', 'children': ['30', '33']},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': 'is'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '32', 'type': 'None', 'children': []},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '45']},{'id': '42', 'type': 'pattern_list', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'extra_actions'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'extra_args_parser'},{'id': '49', 'type': 'argument_list', 'children': []},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'extra_args'},{'id': '53', 'type': 'list_comprehension', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'act'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'dest'},{'id': '57', 'type': 'for_in_clause', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'act'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'extra_actions'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': '_get_optional_args'},{'id': '67', 'type': 'argument_list', 'children': ['68', '69', '70']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'extra_args'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '70', 'type': 'dictionary_splat', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '72', 'type': 'return_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'read_samples'},{'id': '77', 'type': 'argument_list', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '79', 'type': 'dictionary_splat', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'kwargs'} | def samples_from_cli(self, opts, parameters=None, **kwargs):
if parameters is None and opts.parameters is None:
parameters = self.variable_args
elif parameters is None:
parameters = opts.parameters
_, extra_actions = self.extra_args_parser()
extra_args = [act.dest for act in extra_actions]
kwargs = self._get_optional_args(extra_args, opts, **kwargs)
return self.read_samples(parameters, **kwargs) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'data_from_cli'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '5', 'type': 'block', 'children': ['6', '13', '20', '33', '44', '58', '142', '146', '150', '154', '161', '198', '215', '265']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'gates'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'gates_from_cli'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'psd_gates'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'psd_gates_from_cli'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'instruments'},{'id': '23', 'type': 'conditional_expression', 'children': ['24', '27', '32'], 'value': 'if'},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'instruments'},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '31'], 'value': 'is'},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'instruments'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'list', 'children': [], 'value': '[]'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'strain_dict'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'strain_from_cli_multi_ifos'},{'id': '38', 'type': 'argument_list', 'children': ['39', '40', '41']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'instruments'},{'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'precision'},{'id': '43', 'type': 'string', 'children': [], 'value': '"double"'},{'id': '44', 'type': 'if_statement', 'children': ['45', '49']},{'id': '45', 'type': 'not_operator', 'children': ['46']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'gate_overwhitened'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'strain_dict'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'apply_gates_to_td'},{'id': '55', 'type': 'argument_list', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'strain_dict'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'gates'},{'id': '58', 'type': 'if_statement', 'children': ['59', '66', '122', '136']},{'id': '59', 'type': 'boolean_operator', 'children': ['60', '63'], 'value': 'and'},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'psd_start_time'},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'psd_end_time'},{'id': '66', 'type': 'block', 'children': ['67', '76', '80', '88', '96', '107', '114']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'concatenated_string', 'children': ['74', '75']},{'id': '74', 'type': 'string', 'children': [], 'value': '"Will generate a different time series for PSD "'},{'id': '75', 'type': 'string', 'children': [], 'value': '"estimation"'},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'psd_opts'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'psd_opts'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'gps_start_time'},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'psd_opts'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'psd_start_time'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'psd_opts'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'gps_end_time'},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'psd_opts'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'psd_end_time'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'psd_strain_dict'},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'strain_from_cli_multi_ifos'},{'id': '101', 'type': 'argument_list', 'children': ['102', '103', '104']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'psd_opts'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'instruments'},{'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'precision'},{'id': '106', 'type': 'string', 'children': [], 'value': '"double"'},{'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': 'logging'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'string', 'children': [], 'value': '"Applying gates to PSD data"'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'psd_strain_dict'},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'apply_gates_to_td'},{'id': '119', 'type': 'argument_list', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'psd_strain_dict'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'psd_gates'},{'id': '122', 'type': 'elif_clause', 'children': ['123', '130']},{'id': '123', 'type': 'boolean_operator', 'children': ['124', '127'], 'value': 'or'},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'psd_start_time'},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'psd_end_time'},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'raise_statement', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'string', 'children': [], 'value': '"Must give --psd-start-time and --psd-end-time"'},{'id': '136', 'type': 'else_clause', 'children': ['137']},{'id': '137', 'type': 'block', 'children': ['138']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'psd_strain_dict'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'strain_dict'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'stilde_dict'},{'id': '145', 'type': 'dictionary', 'children': []},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'length_dict'},{'id': '149', 'type': 'dictionary', 'children': []},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'delta_f_dict'},{'id': '153', 'type': 'dictionary', 'children': []},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'low_frequency_cutoff_dict'},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'low_frequency_cutoff_from_cli'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '161', 'type': 'for_statement', 'children': ['162', '163', '164']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'ifo'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'instruments'},{'id': '164', 'type': 'block', 'children': ['165', '177', '188']},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '170']},{'id': '167', 'type': 'subscript', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'stilde_dict'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'ifo'},{'id': '170', 'type': 'call', 'children': ['171', '176']},{'id': '171', 'type': 'attribute', 'children': ['172', '175']},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'strain_dict'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'ifo'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'to_frequencyseries'},{'id': '176', 'type': 'argument_list', 'children': []},{'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': 'length_dict'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'ifo'},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'subscript', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'stilde_dict'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'ifo'},{'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': 'delta_f_dict'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'ifo'},{'id': '193', 'type': 'attribute', 'children': ['194', '197']},{'id': '194', 'type': 'subscript', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'stilde_dict'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'ifo'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'delta_f'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'psd_dict'},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'psd_from_cli_multi_ifos'},{'id': '203', 'type': 'argument_list', 'children': ['204', '205', '206', '207', '208', '209', '212']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'length_dict'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'delta_f_dict'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'low_frequency_cutoff_dict'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'instruments'},{'id': '209', 'type': 'keyword_argument', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'strain_dict'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'psd_strain_dict'},{'id': '212', 'type': 'keyword_argument', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'precision'},{'id': '214', 'type': 'string', 'children': [], 'value': '"double"'},{'id': '215', 'type': 'if_statement', 'children': ['216', '225']},{'id': '216', 'type': 'boolean_operator', 'children': ['217', '220'], 'value': 'and'},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'gate_overwhitened'},{'id': '220', 'type': 'comparison_operator', 'children': ['221', '224'], 'value': 'is'},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'gate'},{'id': '224', 'type': 'None', 'children': []},{'id': '225', 'type': 'block', 'children': ['226', '233', '245', '253']},{'id': '226', 'type': 'expression_statement', 'children': ['227']},{'id': '227', 'type': 'call', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'string', 'children': [], 'value': '"Applying gates to overwhitened data"'},{'id': '233', 'type': 'for_statement', 'children': ['234', '235', '236']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'ifo'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'gates'},{'id': '236', 'type': 'block', 'children': ['237']},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'augmented_assignment', 'children': ['239', '242'], 'value': '/='},{'id': '239', 'type': 'subscript', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'stilde_dict'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'ifo'},{'id': '242', 'type': 'subscript', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'psd_dict'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'ifo'},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'assignment', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'stilde_dict'},{'id': '248', 'type': 'call', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'apply_gates_to_fd'},{'id': '250', 'type': 'argument_list', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'stilde_dict'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'gates'},{'id': '253', 'type': 'for_statement', 'children': ['254', '255', '256']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'ifo'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'gates'},{'id': '256', 'type': 'block', 'children': ['257']},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'augmented_assignment', 'children': ['259', '262'], 'value': '*='},{'id': '259', 'type': 'subscript', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'stilde_dict'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'ifo'},{'id': '262', 'type': 'subscript', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'psd_dict'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'ifo'},{'id': '265', 'type': 'return_statement', 'children': ['266']},{'id': '266', 'type': 'expression_list', 'children': ['267', '268', '269']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'strain_dict'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'stilde_dict'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'psd_dict'} | def data_from_cli(opts):
gates = gates_from_cli(opts)
psd_gates = psd_gates_from_cli(opts)
instruments = opts.instruments if opts.instruments is not None else []
strain_dict = strain_from_cli_multi_ifos(opts, instruments,
precision="double")
if not opts.gate_overwhitened:
strain_dict = apply_gates_to_td(strain_dict, gates)
if opts.psd_start_time and opts.psd_end_time:
logging.info("Will generate a different time series for PSD "
"estimation")
psd_opts = opts
psd_opts.gps_start_time = psd_opts.psd_start_time
psd_opts.gps_end_time = psd_opts.psd_end_time
psd_strain_dict = strain_from_cli_multi_ifos(psd_opts,
instruments,
precision="double")
logging.info("Applying gates to PSD data")
psd_strain_dict = apply_gates_to_td(psd_strain_dict, psd_gates)
elif opts.psd_start_time or opts.psd_end_time:
raise ValueError("Must give --psd-start-time and --psd-end-time")
else:
psd_strain_dict = strain_dict
stilde_dict = {}
length_dict = {}
delta_f_dict = {}
low_frequency_cutoff_dict = low_frequency_cutoff_from_cli(opts)
for ifo in instruments:
stilde_dict[ifo] = strain_dict[ifo].to_frequencyseries()
length_dict[ifo] = len(stilde_dict[ifo])
delta_f_dict[ifo] = stilde_dict[ifo].delta_f
psd_dict = psd_from_cli_multi_ifos(
opts, length_dict, delta_f_dict, low_frequency_cutoff_dict,
instruments, strain_dict=psd_strain_dict, precision="double")
if opts.gate_overwhitened and opts.gate is not None:
logging.info("Applying gates to overwhitened data")
for ifo in gates:
stilde_dict[ifo] /= psd_dict[ifo]
stilde_dict = apply_gates_to_fd(stilde_dict, gates)
for ifo in gates:
stilde_dict[ifo] *= psd_dict[ifo]
return strain_dict, stilde_dict, psd_dict |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '7', 'type': 'unary_operator', 'children': ['8'], 'value': '-'},{'id': '8', 'type': 'integer', 'children': [], 'value': '1'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '11', 'type': 'string', 'children': [], 'value': "'quicksort'"},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'try_statement', 'children': ['17', '36']},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '25']},{'id': '20', 'type': 'attribute', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'recarray'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27', '30', '33']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '36', 'type': 'except_clause', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '38', 'type': 'block', 'children': ['39', '51']},{'id': '39', 'type': 'if_statement', 'children': ['40', '45']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'raise_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'string', 'children': [], 'value': '"Cannot process more than one order field"'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '57']},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'slice', 'children': ['56']},{'id': '56', 'type': 'colon', 'children': []},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'order'} | def sort(self, axis=-1, kind='quicksort', order=None):
try:
numpy.recarray.sort(self, axis=axis, kind=kind, order=order)
except ValueError:
if isinstance(order, list):
raise ValueError("Cannot process more than one order field")
self[:] = self[numpy.argsort(self[order])] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'emit_containers'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'containers'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '8', 'type': 'True', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '28', '47']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'containers'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'containers'},{'id': '17', 'type': 'keyword_argument', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '19', 'type': 'lambda', 'children': ['20', '22']},{'id': '20', 'type': 'lambda_parameters', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'task_definition'},{'id': '31', 'type': 'dictionary', 'children': ['32', '37', '40']},{'id': '32', 'type': 'pair', 'children': ['33', '34']},{'id': '33', 'type': 'string', 'children': [], 'value': "'family'"},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'family'},{'id': '37', 'type': 'pair', 'children': ['38', '39']},{'id': '38', 'type': 'string', 'children': [], 'value': "'containerDefinitions'"},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'containers'},{'id': '40', 'type': 'pair', 'children': ['41', '42']},{'id': '41', 'type': 'string', 'children': [], 'value': "'volumes'"},{'id': '42', 'type': 'boolean_operator', 'children': ['43', '46'], 'value': 'or'},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'volumes'},{'id': '46', 'type': 'list', 'children': [], 'value': '[]'},{'id': '47', 'type': 'if_statement', 'children': ['48', '49', '63']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'return_statement', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '55', 'type': 'argument_list', 'children': ['56', '57', '60']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'task_definition'},{'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '59', 'type': 'integer', 'children': [], 'value': '4'},{'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '62', 'type': 'True', 'children': []},{'id': '63', 'type': 'else_clause', 'children': ['64']},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'return_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'task_definition'} | def emit_containers(self, containers, verbose=True):
containers = sorted(containers, key=lambda c: c.get('name'))
task_definition = {
'family': self.family,
'containerDefinitions': containers,
'volumes': self.volumes or []
}
if verbose:
return json.dumps(task_definition, indent=4, sort_keys=True)
else:
return json.dumps(task_definition) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_completions'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'completions_gen'},{'id': '5', 'type': 'block', 'children': ['6', '12', '45']},{'id': '6', 'type': 'import_from_statement', 'children': ['7', '10']},{'id': '7', 'type': 'dotted_name', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'knack'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '10', 'type': 'dotted_name', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'REQUIRED_TAG'},{'id': '12', 'type': 'function_definition', 'children': ['13', '14', '16']},{'id': '13', 'type': 'function_name', 'children': [], 'value': '_get_weight'},{'id': '14', 'type': 'parameters', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '16', 'type': 'block', 'children': ['17', '21', '39']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '20', 'type': 'string', 'children': [], 'value': "''"},{'id': '21', 'type': 'if_statement', 'children': ['22', '34']},{'id': '22', 'type': 'boolean_operator', 'children': ['23', '26'], 'value': 'and'},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'display_meta'},{'id': '26', 'type': 'call', 'children': ['27', '32']},{'id': '27', 'type': 'attribute', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'display_meta'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'REQUIRED_TAG'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '38', 'type': 'string', 'children': [], 'value': "' '"},{'id': '39', 'type': 'return_statement', 'children': ['40']},{'id': '40', 'type': 'binary_operator', 'children': ['41', '42'], 'value': '+'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '45', 'type': 'return_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'completions_gen'},{'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '52', 'type': 'identifier', 'children': [], 'value': '_get_weight'} | def sort_completions(completions_gen):
from knack.help import REQUIRED_TAG
def _get_weight(val):
priority = ''
if val.display_meta and val.display_meta.startswith(REQUIRED_TAG):
priority = ' '
return priority + val.text
return sorted(completions_gen, key=_get_weight) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'attr_list'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '10']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'block', 'children': ['14', '23', '29']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'a_list'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21', '22']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '23', 'type': 'if_statement', 'children': ['24', '26']},{'id': '24', 'type': 'not_operator', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'return_statement', 'children': ['28']},{'id': '28', 'type': 'string', 'children': [], 'value': "''"},{'id': '29', 'type': 'return_statement', 'children': ['30']},{'id': '30', 'type': 'binary_operator', 'children': ['31', '32'], 'value': '%'},{'id': '31', 'type': 'string', 'children': [], 'value': "' [%s]'"},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'content'} | def attr_list(label=None, kwargs=None, attributes=None):
content = a_list(label, kwargs, attributes)
if not content:
return ''
return ' [%s]' % content |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'mapping_items'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': '_iteritems'},{'id': '7', 'type': 'attribute', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': '_compat'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '10', 'type': 'block', 'children': ['11', '30']},{'id': '11', 'type': 'if_statement', 'children': ['12', '18']},{'id': '12', 'type': 'comparison_operator', 'children': ['13', '17'], 'value': 'is'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'return_statement', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_iteritems'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '30', 'type': 'return_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': '_iteritems'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'mapping'} | def mapping_items(mapping, _iteritems=_compat.iteritems):
if type(mapping) is dict:
return iter(sorted(_iteritems(mapping)))
return _iteritems(mapping) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'convert_tensor_to_probability_map'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'scope'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '7', 'type': 'block', 'children': ['8', '10', '22', '33', '200', '212', '333']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'string', 'children': [], 'value': "'''\n This converter tries to convert a special operator 'TensorToProbabilityMap' into a sequence of some ONNX operators.\n Those operators are used to create a dictionary in which keys are class labels and values are the associated\n probabilities. We assume that the elements in the given probability tensor are aligned with the class labels\n specified in the CoreML model.\n Notice that ONNX<1.2 doesn't support a CoreML classifier with a batch size larger than one because old ONNX ZipMap\n is not able to produce a sequence of dictionaries. This issue has been fixed in ONNX-1.2.\n '''"},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '13', 'type': 'dictionary', 'children': ['14']},{'id': '14', 'type': 'pair', 'children': ['15', '16']},{'id': '15', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'scope'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'get_unique_operator_name'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'string', 'children': [], 'value': "'ZipMap'"},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'model_type'},{'id': '25', 'type': 'call', 'children': ['26', '31']},{'id': '26', 'type': 'attribute', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'raw_operator'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'WhichOneof'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'string', 'children': [], 'value': "'Type'"},{'id': '33', 'type': 'if_statement', 'children': ['34', '37', '113', '193']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': '=='},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'model_type'},{'id': '36', 'type': 'string', 'children': [], 'value': "'neuralNetworkClassifier'"},{'id': '37', 'type': 'block', 'children': ['38', '46']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '41', 'type': 'attribute', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'raw_operator'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'neuralNetworkClassifier'},{'id': '46', 'type': 'if_statement', 'children': ['47', '55', '77', '106']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '54'], 'value': '=='},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'WhichOneof'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'string', 'children': [], 'value': "'ClassLabels'"},{'id': '54', 'type': 'string', 'children': [], 'value': "'stringClassLabels'"},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '61']},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '60', 'type': 'string', 'children': [], 'value': "'classlabels_strings'"},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '63', 'type': 'generator_expression', 'children': ['64', '70']},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '70', 'type': 'for_in_clause', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '72', 'type': 'attribute', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'stringClassLabels'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'vector'},{'id': '77', 'type': 'elif_clause', 'children': ['78', '86']},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '85'], 'value': '=='},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'WhichOneof'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'string', 'children': [], 'value': "'ClassLabels'"},{'id': '85', 'type': 'string', 'children': [], 'value': "'int64ClassLabels'"},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '92']},{'id': '89', 'type': 'subscript', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '91', 'type': 'string', 'children': [], 'value': "'classlabels_int64s'"},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '94', 'type': 'generator_expression', 'children': ['95', '99']},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '99', 'type': 'for_in_clause', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '101', 'type': 'attribute', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'int64ClassLabels'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'vector'},{'id': '106', 'type': 'else_clause', 'children': ['107']},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'raise_statement', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'string', 'children': [], 'value': "'Unknown label type found'"},{'id': '113', 'type': 'elif_clause', 'children': ['114', '117']},{'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': '=='},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'model_type'},{'id': '116', 'type': 'string', 'children': [], 'value': "'pipelineClassifier'"},{'id': '117', 'type': 'block', 'children': ['118', '126']},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '121', 'type': 'attribute', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'raw_operator'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'pipelineClassifier'},{'id': '126', 'type': 'if_statement', 'children': ['127', '135', '157', '186']},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '134'], 'value': '=='},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'WhichOneof'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'string', 'children': [], 'value': "'ClassLabels'"},{'id': '134', 'type': 'string', 'children': [], 'value': "'stringClassLabels'"},{'id': '135', 'type': 'block', 'children': ['136']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '141']},{'id': '138', 'type': 'subscript', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '140', 'type': 'string', 'children': [], 'value': "'classlabels_strings'"},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '143', 'type': 'generator_expression', 'children': ['144', '150']},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '150', 'type': 'for_in_clause', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '152', 'type': 'attribute', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'stringClassLabels'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'vector'},{'id': '157', 'type': 'elif_clause', 'children': ['158', '166']},{'id': '158', 'type': 'comparison_operator', 'children': ['159', '165'], 'value': '=='},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'WhichOneof'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'string', 'children': [], 'value': "'ClassLabels'"},{'id': '165', 'type': 'string', 'children': [], 'value': "'int64ClassLabels'"},{'id': '166', 'type': 'block', 'children': ['167']},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '172']},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '171', 'type': 'string', 'children': [], 'value': "'classlabels_int64s'"},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '174', 'type': 'generator_expression', 'children': ['175', '179']},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '179', 'type': 'for_in_clause', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '181', 'type': 'attribute', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'int64ClassLabels'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'vector'},{'id': '186', 'type': 'else_clause', 'children': ['187']},{'id': '187', 'type': 'block', 'children': ['188']},{'id': '188', 'type': 'raise_statement', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'string', 'children': [], 'value': "'Unknown label type found'"},{'id': '193', 'type': 'else_clause', 'children': ['194']},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'raise_statement', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'string', 'children': [], 'value': "'Only neural network classifiers and pipeline classifiers are supported'"},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'input_shape'},{'id': '203', 'type': 'attribute', 'children': ['204', '211']},{'id': '204', 'type': 'attribute', 'children': ['205', '210']},{'id': '205', 'type': 'subscript', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '209', 'type': 'integer', 'children': [], 'value': '0'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '212', 'type': 'if_statement', 'children': ['213', '227', '321']},{'id': '213', 'type': 'comparison_operator', 'children': ['214', '226'], 'value': '!='},{'id': '214', 'type': 'call', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'attribute', 'children': ['218', '225']},{'id': '218', 'type': 'attribute', 'children': ['219', '224']},{'id': '219', 'type': 'subscript', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '223', 'type': 'integer', 'children': [], 'value': '0'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '226', 'type': 'integer', 'children': [], 'value': '2'},{'id': '227', 'type': 'block', 'children': ['228', '248', '293', '302']},{'id': '228', 'type': 'if_statement', 'children': ['229', '234', '241']},{'id': '229', 'type': 'comparison_operator', 'children': ['230', '233'], 'value': '!='},{'id': '230', 'type': 'subscript', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'input_shape'},{'id': '232', 'type': 'integer', 'children': [], 'value': '0'},{'id': '233', 'type': 'string', 'children': [], 'value': "'None'"},{'id': '234', 'type': 'block', 'children': ['235']},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '238', 'type': 'subscript', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'input_shape'},{'id': '240', 'type': 'integer', 'children': [], 'value': '0'},{'id': '241', 'type': 'else_clause', 'children': ['242']},{'id': '242', 'type': 'block', 'children': ['243']},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'assignment', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '246', 'type': 'unary_operator', 'children': ['247'], 'value': '-'},{'id': '247', 'type': 'integer', 'children': [], 'value': '1'},{'id': '248', 'type': 'if_statement', 'children': ['249', '266', '286']},{'id': '249', 'type': 'call', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '251', 'type': 'generator_expression', 'children': ['252', '259']},{'id': '252', 'type': 'call', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '254', 'type': 'argument_list', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'numbers'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'Integral'},{'id': '259', 'type': 'for_in_clause', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '261', 'type': 'subscript', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'input_shape'},{'id': '263', 'type': 'slice', 'children': ['264', '265']},{'id': '264', 'type': 'integer', 'children': [], 'value': '1'},{'id': '265', 'type': 'colon', 'children': []},{'id': '266', 'type': 'block', 'children': ['267', '271']},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'assignment', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'C'},{'id': '270', 'type': 'integer', 'children': [], 'value': '1'},{'id': '271', 'type': 'for_statement', 'children': ['272', '273', '278']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '273', 'type': 'subscript', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'input_shape'},{'id': '275', 'type': 'slice', 'children': ['276', '277']},{'id': '276', 'type': 'integer', 'children': [], 'value': '1'},{'id': '277', 'type': 'colon', 'children': []},{'id': '278', 'type': 'block', 'children': ['279']},{'id': '279', 'type': 'expression_statement', 'children': ['280']},{'id': '280', 'type': 'augmented_assignment', 'children': ['281', '282'], 'value': '*='},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'C'},{'id': '282', 'type': 'call', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '284', 'type': 'argument_list', 'children': ['285']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '286', 'type': 'else_clause', 'children': ['287']},{'id': '287', 'type': 'block', 'children': ['288']},{'id': '288', 'type': 'expression_statement', 'children': ['289']},{'id': '289', 'type': 'assignment', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'C'},{'id': '291', 'type': 'unary_operator', 'children': ['292'], 'value': '-'},{'id': '292', 'type': 'integer', 'children': [], 'value': '1'},{'id': '293', 'type': 'expression_statement', 'children': ['294']},{'id': '294', 'type': 'assignment', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'buffer_name'},{'id': '296', 'type': 'call', 'children': ['297', '300']},{'id': '297', 'type': 'attribute', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'scope'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'get_unique_variable_name'},{'id': '300', 'type': 'argument_list', 'children': ['301']},{'id': '301', 'type': 'string', 'children': [], 'value': "'buffer'"},{'id': '302', 'type': 'expression_statement', 'children': ['303']},{'id': '303', 'type': 'call', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'apply_reshape'},{'id': '305', 'type': 'argument_list', 'children': ['306', '307', '314', '315', '316']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'scope'},{'id': '307', 'type': 'attribute', 'children': ['308', '313']},{'id': '308', 'type': 'subscript', 'children': ['309', '312']},{'id': '309', 'type': 'attribute', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '312', 'type': 'integer', 'children': [], 'value': '0'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'full_name'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'buffer_name'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '316', 'type': 'keyword_argument', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'desired_shape'},{'id': '318', 'type': 'list', 'children': ['319', '320'], 'value': '[N, C]'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'C'},{'id': '321', 'type': 'else_clause', 'children': ['322']},{'id': '322', 'type': 'block', 'children': ['323']},{'id': '323', 'type': 'expression_statement', 'children': ['324']},{'id': '324', 'type': 'assignment', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'buffer_name'},{'id': '326', 'type': 'attribute', 'children': ['327', '332']},{'id': '327', 'type': 'subscript', 'children': ['328', '331']},{'id': '328', 'type': 'attribute', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '331', 'type': 'integer', 'children': [], 'value': '0'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'full_name'},{'id': '333', 'type': 'expression_statement', 'children': ['334']},{'id': '334', 'type': 'call', 'children': ['335', '338']},{'id': '335', 'type': 'attribute', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'add_node'},{'id': '338', 'type': 'argument_list', 'children': ['339', '340', '341', '348', '351']},{'id': '339', 'type': 'string', 'children': [], 'value': "'ZipMap'"},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'buffer_name'},{'id': '341', 'type': 'attribute', 'children': ['342', '347']},{'id': '342', 'type': 'subscript', 'children': ['343', '346']},{'id': '343', 'type': 'attribute', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'outputs'},{'id': '346', 'type': 'integer', 'children': [], 'value': '0'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'full_name'},{'id': '348', 'type': 'keyword_argument', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'op_domain'},{'id': '350', 'type': 'string', 'children': [], 'value': "'ai.onnx.ml'"},{'id': '351', 'type': 'dictionary_splat', 'children': ['352']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'attrs'} | def convert_tensor_to_probability_map(scope, operator, container):
'''
This converter tries to convert a special operator 'TensorToProbabilityMap' into a sequence of some ONNX operators.
Those operators are used to create a dictionary in which keys are class labels and values are the associated
probabilities. We assume that the elements in the given probability tensor are aligned with the class labels
specified in the CoreML model.
Notice that ONNX<1.2 doesn't support a CoreML classifier with a batch size larger than one because old ONNX ZipMap
is not able to produce a sequence of dictionaries. This issue has been fixed in ONNX-1.2.
'''
attrs = {'name': scope.get_unique_operator_name('ZipMap')}
model_type = operator.raw_operator.WhichOneof('Type')
if model_type == 'neuralNetworkClassifier':
model = operator.raw_operator.neuralNetworkClassifier
if model.WhichOneof('ClassLabels') == 'stringClassLabels':
attrs['classlabels_strings'] = list(s.encode('utf-8') for s in model.stringClassLabels.vector)
elif model.WhichOneof('ClassLabels') == 'int64ClassLabels':
attrs['classlabels_int64s'] = list(int(i) for i in model.int64ClassLabels.vector)
else:
raise ValueError('Unknown label type found')
elif model_type == 'pipelineClassifier':
model = operator.raw_operator.pipelineClassifier
if model.WhichOneof('ClassLabels') == 'stringClassLabels':
attrs['classlabels_strings'] = list(s.encode('utf-8') for s in model.stringClassLabels.vector)
elif model.WhichOneof('ClassLabels') == 'int64ClassLabels':
attrs['classlabels_int64s'] = list(int(i) for i in model.int64ClassLabels.vector)
else:
raise ValueError('Unknown label type found')
else:
raise TypeError('Only neural network classifiers and pipeline classifiers are supported')
input_shape = operator.inputs[0].type.shape
if len(operator.inputs[0].type.shape) != 2:
if input_shape[0] != 'None':
N = input_shape[0]
else:
N = -1
if all(isinstance(i, numbers.Integral) for i in input_shape[1:]):
C = 1
for i in input_shape[1:]:
C *= int(i)
else:
C = -1
buffer_name = scope.get_unique_variable_name('buffer')
apply_reshape(scope, operator.inputs[0].full_name, buffer_name, container, desired_shape=[N, C])
else:
buffer_name = operator.inputs[0].full_name
container.add_node('ZipMap', buffer_name, operator.outputs[0].full_name,
op_domain='ai.onnx.ml', **attrs) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.