sequence
stringlengths 1.19k
35k
| code
stringlengths 75
8.58k
|
---|---|
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'intersect_range_array'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'bed1'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'beds2'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'payload'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'is_sorted'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '24', '28', '105', '113']}, {'id': '13', 'type': 'if_statement', 'children': ['14', '16']}; {'id': '14', 'type': 'not_operator', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'is_sorted'}; {'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': 'beds2'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'sort_ranges'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'beds2'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '27', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '28', 'type': 'for_statement', 'children': ['29', '30', '31']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'bed2'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'beds2'}, {'id': '31', 'type': 'block', 'children': ['32', '41']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'cval'}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'bed2'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'cmp'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'bed1'}, {'id': '41', 'type': 'if_statement', 'children': ['42', '46', '48', '99']}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': '=='}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'cval'}; {'id': '44', 'type': 'unary_operator', 'children': ['45'], 'value': '-'}, {'id': '45', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '46', 'type': 'block', 'children': ['47']}, {'id': '47', 'type': 'continue_statement', 'children': []}; {'id': '48', 'type': 'elif_clause', 'children': ['49', '52']}, {'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': '=='}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'cval'}, {'id': '51', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '52', 'type': 'block', 'children': ['53', '65', '82']}, {'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': 'output'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'bed1'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'intersect'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'bed2'}, {'id': '65', 'type': 'if_statement', 'children': ['66', '69']}; {'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': '=='}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'payload'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '78']}; {'id': '72', 'type': 'attribute', 'children': ['73', '77']}, {'id': '73', 'type': 'subscript', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '75', 'type': 'unary_operator', 'children': ['76'], 'value': '-'}; {'id': '76', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'set_payload'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'bed1'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'payload'}; {'id': '82', 'type': 'if_statement', 'children': ['83', '86']}, {'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': '=='}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'payload'}, {'id': '85', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '86', 'type': 'block', 'children': ['87']}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '95']}, {'id': '89', 'type': 'attribute', 'children': ['90', '94']}; {'id': '90', 'type': 'subscript', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '92', 'type': 'unary_operator', 'children': ['93'], 'value': '-'}, {'id': '93', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'set_payload'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'bed2'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'payload'}, {'id': '99', 'type': 'elif_clause', 'children': ['100', '103']}; {'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': '=='}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'cval'}; {'id': '102', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'break_statement', 'children': []}, {'id': '105', 'type': 'if_statement', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'payload'}, {'id': '107', 'type': 'block', 'children': ['108']}; {'id': '108', 'type': 'return_statement', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'sort_ranges'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '113', 'type': 'return_statement', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'merge_ranges'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'output'} | def intersect_range_array(bed1,beds2,payload=None,is_sorted=False):
if not is_sorted: beds2 = sort_ranges(beds2)
output = []
for bed2 in beds2:
cval = bed2.cmp(bed1)
if cval == -1: continue
elif cval == 0:
output.append(bed1.intersect(bed2))
if payload==1:
output[-1].set_payload(bed1.payload)
if payload==2:
output[-1].set_payload(bed2.payload)
elif cval == 1: break
if payload: return sort_ranges(output)
return merge_ranges(output) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_genomic_ranges'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'rngs'}, {'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': 'rngs'}, {'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', '23']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'chr'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'end'} | def sort_genomic_ranges(rngs):
return sorted(rngs, key=lambda x: (x.chr, x.start, x.end)) |
{'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': 'dependencies'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'start_nodes'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '22', '33', '51', '95', '117']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'retval'}; {'id': '10', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '11', 'type': 'function_definition', 'children': ['12', '13', '15']}; {'id': '12', 'type': 'function_name', 'children': [], 'value': 'edges'}, {'id': '13', 'type': 'parameters', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'return_statement', 'children': ['17']}, {'id': '17', 'type': 'subscript', 'children': ['18', '21']}; {'id': '18', 'type': 'subscript', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'dependencies'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '21', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '22', 'type': 'function_definition', 'children': ['23', '24', '26']}, {'id': '23', 'type': 'function_name', 'children': [], 'value': 'in_degree'}; {'id': '24', 'type': 'parameters', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'return_statement', 'children': ['28']}; {'id': '28', 'type': 'subscript', 'children': ['29', '32']}, {'id': '29', 'type': 'subscript', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'dependencies'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '32', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '33', 'type': 'function_definition', 'children': ['34', '35', '37']}; {'id': '34', 'type': 'function_name', 'children': [], 'value': 'remove_incoming'}, {'id': '35', 'type': 'parameters', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '45']}; {'id': '40', 'type': 'subscript', 'children': ['41', '44']}, {'id': '41', 'type': 'subscript', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'dependencies'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '45', 'type': 'binary_operator', 'children': ['46', '50'], 'value': '-'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'in_degree'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '50', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '51', 'type': 'while_statement', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'start_nodes'}, {'id': '53', 'type': 'block', 'children': ['54', '62', '69']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'start_nodes'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '61', 'type': 'argument_list', 'children': []}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'retval'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '69', 'type': 'for_statement', 'children': ['70', '71', '75']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'edges'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '75', 'type': 'block', 'children': ['76', '81']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'remove_incoming'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '81', 'type': 'if_statement', 'children': ['82', '87']}; {'id': '82', 'type': 'not_operator', 'children': ['83']}, {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'in_degree'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'start_nodes'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'leftover_nodes'}; {'id': '98', 'type': 'list_comprehension', 'children': ['99', '100', '110']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '100', 'type': 'for_in_clause', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'dependencies'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '109', 'type': 'argument_list', 'children': []}; {'id': '110', 'type': 'if_clause', 'children': ['111']}, {'id': '111', 'type': 'comparison_operator', 'children': ['112', '116'], 'value': '>'}; {'id': '112', 'type': 'call', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'in_degree'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '116', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '117', 'type': 'if_statement', 'children': ['118', '119', '125']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'leftover_nodes'}, {'id': '119', 'type': 'block', 'children': ['120']}; {'id': '120', 'type': 'raise_statement', 'children': ['121']}, {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'CyclicDependency'}, {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'leftover_nodes'}, {'id': '125', 'type': 'else_clause', 'children': ['126']}; {'id': '126', 'type': 'block', 'children': ['127']}, {'id': '127', 'type': 'return_statement', 'children': ['128']} | def topological_sort(dependencies, start_nodes):
retval = []
def edges(node): return dependencies[node][1]
def in_degree(node): return dependencies[node][0]
def remove_incoming(node): dependencies[node][0] = in_degree(node) - 1
while start_nodes:
node = start_nodes.pop()
retval.append(node)
for child in edges(node):
remove_incoming(child)
if not in_degree(child):
start_nodes.append(child)
leftover_nodes = [node for node in list(dependencies.keys())
if in_degree(node) > 0]
if leftover_nodes:
raise CyclicDependency(leftover_nodes)
else:
return retval |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_do_parse'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'fmt'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'force_types'}; {'id': '8', 'type': 'block', 'children': ['9', '13', '19', '189']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '12', 'type': 'dictionary', 'children': []}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': '_check_lib_installed'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'fmt'}; {'id': '18', 'type': 'string', 'children': [], 'value': "'parse'"}, {'id': '19', 'type': 'if_statement', 'children': ['20', '23', '44', '78', '112', '155', '172', '186']}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': '=='}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'fmt'}; {'id': '22', 'type': 'string', 'children': [], 'value': "'ini'"}, {'id': '23', 'type': 'block', 'children': ['24', '36']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'configobj'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'ConfigObj'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '43', 'type': 'argument_list', 'children': []}; {'id': '44', 'type': 'elif_clause', 'children': ['45', '48']}, {'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': '=='}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'fmt'}, {'id': '47', 'type': 'string', 'children': [], 'value': "'json'"}; {'id': '48', 'type': 'block', 'children': ['49', '66']}, {'id': '49', 'type': 'if_statement', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'PY3'}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'io'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'TextIOWrapper'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'load'}, {'id': '73', 'type': 'argument_list', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '78', 'type': 'elif_clause', 'children': ['79', '82']}, {'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': '=='}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'fmt'}, {'id': '81', 'type': 'string', 'children': [], 'value': "'json5'"}; {'id': '82', 'type': 'block', 'children': ['83', '100']}, {'id': '83', 'type': 'if_statement', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'PY3'}, {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'io'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'TextIOWrapper'}, {'id': '95', 'type': 'argument_list', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'json5'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'load'}, {'id': '107', 'type': 'argument_list', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '109', 'type': 'keyword_argument', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '112', 'type': 'elif_clause', 'children': ['113', '116']}, {'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': '=='}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'fmt'}, {'id': '115', 'type': 'string', 'children': [], 'value': "'toml'"}; {'id': '116', 'type': 'block', 'children': ['117', '129', '146']}, {'id': '117', 'type': 'if_statement', 'children': ['118', '123']}; {'id': '118', 'type': 'not_operator', 'children': ['119']}, {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': '_is_utf8'}, {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '123', 'type': 'block', 'children': ['124']}; {'id': '124', 'type': 'raise_statement', 'children': ['125']}, {'id': '125', 'type': 'call', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'AnyMarkupError'}, {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'string', 'children': [], 'value': "'toml is always utf-8 encoded according to specification'"}, {'id': '129', 'type': 'if_statement', 'children': ['130', '133']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'PY3'}, {'id': '133', 'type': 'block', 'children': ['134']}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'io'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'TextIOWrapper'}, {'id': '141', 'type': 'argument_list', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '143', 'type': 'keyword_argument', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '149', 'type': 'call', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'toml'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'load'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '155', 'type': 'elif_clause', 'children': ['156', '159']}; {'id': '156', 'type': 'comparison_operator', 'children': ['157', '158'], 'value': '=='}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'fmt'}; {'id': '158', 'type': 'string', 'children': [], 'value': "'xml'"}, {'id': '159', 'type': 'block', 'children': ['160']}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'assignment', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '163', 'type': 'call', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'xmltodict'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '167', 'type': 'argument_list', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '169', 'type': 'keyword_argument', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '172', 'type': 'elif_clause', 'children': ['173', '176']}, {'id': '173', 'type': 'comparison_operator', 'children': ['174', '175'], 'value': '=='}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'fmt'}, {'id': '175', 'type': 'string', 'children': [], 'value': "'yaml'"}; {'id': '176', 'type': 'block', 'children': ['177']}, {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'assignment', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '180', 'type': 'call', 'children': ['181', '184']}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'yaml'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'safe_load'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'inp'}; {'id': '186', 'type': 'else_clause', 'children': ['187']}, {'id': '187', 'type': 'block', 'children': ['188']}; {'id': '188', 'type': 'raise_statement', 'children': []}, {'id': '189', 'type': 'return_statement', 'children': ['190']}; {'id': '190', 'type': 'call', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': '_ensure_proper_types'}; {'id': '192', 'type': 'argument_list', 'children': ['193', '194', '195']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'force_types'} | def _do_parse(inp, fmt, encoding, force_types):
res = {}
_check_lib_installed(fmt, 'parse')
if fmt == 'ini':
cfg = configobj.ConfigObj(inp, encoding=encoding)
res = cfg.dict()
elif fmt == 'json':
if six.PY3:
inp = io.TextIOWrapper(inp, encoding=encoding)
res = json.load(inp, encoding=encoding)
elif fmt == 'json5':
if six.PY3:
inp = io.TextIOWrapper(inp, encoding=encoding)
res = json5.load(inp, encoding=encoding)
elif fmt == 'toml':
if not _is_utf8(encoding):
raise AnyMarkupError('toml is always utf-8 encoded according to specification')
if six.PY3:
inp = io.TextIOWrapper(inp, encoding=encoding)
res = toml.load(inp)
elif fmt == 'xml':
res = xmltodict.parse(inp, encoding=encoding)
elif fmt == 'yaml':
res = yaml.safe_load(inp)
else:
raise
return _ensure_proper_types(res, encoding, force_types) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_do_serialize'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'struct'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'fmt'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '7', 'type': 'block', 'children': ['8', '12', '18', '180']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_check_lib_installed'}, {'id': '15', 'type': 'argument_list', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'fmt'}, {'id': '17', 'type': 'string', 'children': [], 'value': "'serialize'"}; {'id': '18', 'type': 'if_statement', 'children': ['19', '22', '63', '101', '132', '157', '177']}, {'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': '=='}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'fmt'}, {'id': '21', 'type': 'string', 'children': [], 'value': "'ini'"}; {'id': '22', 'type': 'block', 'children': ['23', '34', '50']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'configobj'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'ConfigObj'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '34', 'type': 'for_statement', 'children': ['35', '38', '43']}, {'id': '35', 'type': 'pattern_list', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'struct'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '42', 'type': 'argument_list', 'children': []}, {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '49']}; {'id': '46', 'type': 'subscript', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'string', 'children': [], 'value': "b'\\n'"}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '62', 'type': 'argument_list', 'children': []}, {'id': '63', 'type': 'elif_clause', 'children': ['64', '69']}; {'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': 'in'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'fmt'}; {'id': '66', 'type': 'list', 'children': ['67', '68'], 'value': "['json', 'json5']"}, {'id': '67', 'type': 'string', 'children': [], 'value': "'json'"}; {'id': '68', 'type': 'string', 'children': [], 'value': "'json5'"}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '73', 'type': 'call', 'children': ['74', '99']}; {'id': '74', 'type': 'attribute', 'children': ['75', '98']}, {'id': '75', 'type': 'call', 'children': ['76', '85']}; {'id': '76', 'type': 'attribute', 'children': ['77', '84']}, {'id': '77', 'type': 'parenthesized_expression', 'children': ['78'], 'value': '()'}; {'id': '78', 'type': 'conditional_expression', 'children': ['79', '80', '83'], 'value': 'if'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': '=='}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'fmt'}; {'id': '82', 'type': 'string', 'children': [], 'value': "'json'"}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'json5'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'dumps'}, {'id': '85', 'type': 'argument_list', 'children': ['86', '87', '90', '95']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'struct'}, {'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'indent'}, {'id': '89', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'separators'}; {'id': '92', 'type': 'tuple', 'children': ['93', '94']}, {'id': '93', 'type': 'string', 'children': [], 'value': "','"}; {'id': '94', 'type': 'string', 'children': [], 'value': "': '"}, {'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'ensure_ascii'}, {'id': '97', 'type': 'False', 'children': []}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'encode'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '101', 'type': 'elif_clause', 'children': ['102', '105']}; {'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': '=='}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'fmt'}; {'id': '104', 'type': 'string', 'children': [], 'value': "'toml'"}, {'id': '105', 'type': 'block', 'children': ['106', '118']}; {'id': '106', 'type': 'if_statement', 'children': ['107', '112']}, {'id': '107', 'type': 'not_operator', 'children': ['108']}; {'id': '108', 'type': 'call', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': '_is_utf8'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '112', 'type': 'block', 'children': ['113']}, {'id': '113', 'type': 'raise_statement', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'AnyMarkupError'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}, {'id': '117', 'type': 'string', 'children': [], 'value': "'toml must always be utf-8 encoded according to specification'"}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '121', 'type': 'call', 'children': ['122', '130']}; {'id': '122', 'type': 'attribute', 'children': ['123', '129']}, {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'toml'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'dumps'}, {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'struct'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '132', 'type': 'elif_clause', 'children': ['133', '136']}, {'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': '=='}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'fmt'}, {'id': '135', 'type': 'string', 'children': [], 'value': "'xml'"}; {'id': '136', 'type': 'block', 'children': ['137']}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '140', 'type': 'call', 'children': ['141', '155']}, {'id': '141', 'type': 'attribute', 'children': ['142', '154']}; {'id': '142', 'type': 'call', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'xmltodict'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'unparse'}; {'id': '146', 'type': 'argument_list', 'children': ['147', '148', '151']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'struct'}; {'id': '148', 'type': 'keyword_argument', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'pretty'}; {'id': '150', 'type': 'True', 'children': []}, {'id': '151', 'type': 'keyword_argument', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '153', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'encode'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'string', 'children': [], 'value': "'utf-8'"}, {'id': '157', 'type': 'elif_clause', 'children': ['158', '161']}; {'id': '158', 'type': 'comparison_operator', 'children': ['159', '160'], 'value': '=='}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'fmt'}; {'id': '160', 'type': 'string', 'children': [], 'value': "'yaml'"}, {'id': '161', 'type': 'block', 'children': ['162']}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}, {'id': '163', 'type': 'assignment', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'yaml'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'safe_dump'}, {'id': '169', 'type': 'argument_list', 'children': ['170', '171', '174']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'struct'}, {'id': '171', 'type': 'keyword_argument', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '173', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '174', 'type': 'keyword_argument', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'default_flow_style'}; {'id': '176', 'type': 'False', 'children': []}, {'id': '177', 'type': 'else_clause', 'children': ['178']}; {'id': '178', 'type': 'block', 'children': ['179']}, {'id': '179', 'type': 'raise_statement', 'children': []}; {'id': '180', 'type': 'return_statement', 'children': ['181']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'res'} | def _do_serialize(struct, fmt, encoding):
res = None
_check_lib_installed(fmt, 'serialize')
if fmt == 'ini':
config = configobj.ConfigObj(encoding=encoding)
for k, v in struct.items():
config[k] = v
res = b'\n'.join(config.write())
elif fmt in ['json', 'json5']:
res = (json if fmt == 'json' else json5).dumps(struct,
indent=2,
separators=(',', ': '),
ensure_ascii=False).encode(encoding)
elif fmt == 'toml':
if not _is_utf8(encoding):
raise AnyMarkupError('toml must always be utf-8 encoded according to specification')
res = toml.dumps(struct).encode(encoding)
elif fmt == 'xml':
res = xmltodict.unparse(struct, pretty=True, encoding='utf-8').encode('utf-8')
elif fmt == 'yaml':
res = yaml.safe_dump(struct, encoding='utf-8', default_flow_style=False)
else:
raise
return res |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_header'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'header_text'}, {'id': '5', 'type': 'block', 'children': ['6', '19', '23', '56', '60', '64', '126']}; {'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', '17']}; {'id': '10', 'type': 'attribute', 'children': ['11', '16']}, {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'header_text'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'rstrip'}, {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'string', 'children': [], 'value': '"\\n"'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'rlens'}; {'id': '22', 'type': 'dictionary', 'children': []}, {'id': '23', 'type': 'for_statement', 'children': ['24', '25', '26']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'ln'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '26', 'type': 'block', 'children': ['27', '37']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36']}, {'id': '35', 'type': 'string', 'children': [], 'value': "'@SQ\\tSN:(\\S+)\\tLN:(\\S+)'"}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'ln'}, {'id': '37', 'type': 'if_statement', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '50']}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'rlens'}; {'id': '44', 'type': 'call', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '59', 'type': 'string', 'children': [], 'value': "''"}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'done_lens'}, {'id': '63', 'type': 'False', 'children': []}; {'id': '64', 'type': 'for_statement', 'children': ['65', '66', '67']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'ln'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'lines'}, {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'if_statement', 'children': ['69', '76', '113']}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '73', 'type': 'argument_list', 'children': ['74', '75']}; {'id': '74', 'type': 'string', 'children': [], 'value': "'@SQ\\tSN:'"}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'ln'}; {'id': '76', 'type': 'block', 'children': ['77']}, {'id': '77', 'type': 'if_statement', 'children': ['78', '80']}; {'id': '78', 'type': 'not_operator', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'done_lens'}; {'id': '80', 'type': 'block', 'children': ['81', '85']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'done_lens'}; {'id': '84', 'type': 'True', 'children': []}, {'id': '85', 'type': 'for_statement', 'children': ['86', '87', '95']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'chr'}, {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'rlens'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '94', 'type': 'argument_list', 'children': []}, {'id': '95', 'type': 'block', 'children': ['96']}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'augmented_assignment', 'children': ['98', '99'], 'value': '+='}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '99', 'type': 'binary_operator', 'children': ['100', '112'], 'value': '+'}; {'id': '100', 'type': 'binary_operator', 'children': ['101', '106'], 'value': '+'}, {'id': '101', 'type': 'binary_operator', 'children': ['102', '105'], 'value': '+'}; {'id': '102', 'type': 'binary_operator', 'children': ['103', '104'], 'value': '+'}, {'id': '103', 'type': 'string', 'children': [], 'value': '"@SQ\\tSN:"'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'chr'}, {'id': '105', 'type': 'string', 'children': [], 'value': '"\\tLN:"'}; {'id': '106', 'type': 'call', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'subscript', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'rlens'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'chr'}; {'id': '112', 'type': 'string', 'children': [], 'value': '"\\n"'}, {'id': '113', 'type': 'else_clause', 'children': ['114']}; {'id': '114', 'type': 'block', 'children': ['115']}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'augmented_assignment', 'children': ['117', '118'], 'value': '+='}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '118', 'type': 'binary_operator', 'children': ['119', '125'], 'value': '+'}, {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'ln'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'rstrip'}, {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'string', 'children': [], 'value': '"\\n"'}, {'id': '125', 'type': 'string', 'children': [], 'value': '"\\n"'}; {'id': '126', 'type': 'return_statement', 'children': ['127']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'output'} | def sort_header(header_text):
lines = header_text.rstrip().split("\n")
rlens = {}
for ln in lines:
m = re.match('@SQ\tSN:(\S+)\tLN:(\S+)',ln)
if m:
rlens[m.group(1)] = m.group(2)
output = ''
done_lens = False
for ln in lines:
if re.match('@SQ\tSN:',ln):
if not done_lens:
done_lens = True
for chr in sorted(rlens.keys()):
output += "@SQ\tSN:"+chr+"\tLN:"+str(rlens[chr])+"\n"
else:
output += ln.rstrip("\n")+"\n"
return output |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'direction'}; {'id': '8', 'type': 'string', 'children': [], 'value': '"asc"'}, {'id': '9', 'type': 'block', 'children': ['10', '23', '35']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '17']}, {'id': '11', 'type': 'not_operator', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'basestring'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'raise_statement', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'string', 'children': [], 'value': '"Field should be a string"'}, {'id': '23', 'type': 'if_statement', 'children': ['24', '29']}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'not'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'direction'}; {'id': '26', 'type': 'list', 'children': ['27', '28'], 'value': '["asc", "desc"]'}, {'id': '27', 'type': 'string', 'children': [], 'value': '"asc"'}; {'id': '28', 'type': 'string', 'children': [], 'value': '"desc"'}, {'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': 'ValueError'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'string', 'children': [], 'value': '"Sort direction should be `asc` or `desc`"'}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '42']}, {'id': '37', 'type': 'attribute', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'sorts'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'dictionary', 'children': ['44']}; {'id': '44', 'type': 'pair', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'field'} | def sort(self, field, direction="asc"):
if not isinstance(field, basestring):
raise ValueError("Field should be a string")
if direction not in ["asc", "desc"]:
raise ValueError("Sort direction should be `asc` or `desc`")
self.sorts.append({field: direction}) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'remove_sort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'field_name'}; {'id': '6', 'type': 'block', 'children': ['7']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '12']}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sorts'}; {'id': '12', 'type': 'list_comprehension', 'children': ['13', '19', '26']}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '19', 'type': 'for_in_clause', 'children': ['20', '23']}; {'id': '20', 'type': 'pattern_list', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'sorts'}; {'id': '26', 'type': 'if_clause', 'children': ['27']}, {'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'is'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'field_name'} | def remove_sort(self, field_name):
self.sorts = [dict(field=value) for field, value in self.sorts if field
is not field_name] |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'aggregate_registry_timers'}, {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '8', '27', '31', '100', '106']}, {'id': '5', 'type': 'import_statement', 'children': ['6']}; {'id': '6', 'type': 'dotted_name', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'itertools'}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'timers'}, {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '13', 'type': 'argument_list', 'children': ['14', '19']}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'shared_registry'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '18', 'type': 'argument_list', 'children': []}, {'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '21', 'type': 'lambda', 'children': ['22', '24']}; {'id': '22', 'type': 'lambda_parameters', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'desc'}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'aggregate_timers'}; {'id': '30', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '31', 'type': 'for_statement', 'children': ['32', '35', '49']}; {'id': '32', 'type': 'pattern_list', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'g'}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'itertools'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'groupby'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'timers'}, {'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '43', 'type': 'lambda', 'children': ['44', '46']}; {'id': '44', 'type': 'lambda_parameters', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'desc'}, {'id': '49', 'type': 'block', 'children': ['50', '57', '64', '76', '88']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'group'}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'g'}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'num_calls'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'total_elapsed_ms'}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'sum'}, {'id': '69', 'type': 'generator_expression', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'elapsed_time_ms'}, {'id': '73', 'type': 'for_in_clause', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'first_start_time'}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '81', 'type': 'generator_expression', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'start_time'}, {'id': '85', 'type': 'for_in_clause', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'aggregate_timers'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'tuple', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'first_start_time'}; {'id': '96', 'type': 'tuple', 'children': ['97', '98', '99']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'total_elapsed_ms'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'num_calls'}; {'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': 'aggregate_timers'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '105', 'type': 'argument_list', 'children': []}; {'id': '106', 'type': 'return_statement', 'children': ['107']}, {'id': '107', 'type': 'subscript', 'children': ['108', '113']}; {'id': '108', 'type': 'call', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'list_splat', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'aggregate_timers'}, {'id': '113', 'type': 'integer', 'children': [], 'value': '1'} | def aggregate_registry_timers():
import itertools
timers = sorted(shared_registry.values(), key=lambda t: t.desc)
aggregate_timers = []
for k, g in itertools.groupby(timers, key=lambda t: t.desc):
group = list(g)
num_calls = len(group)
total_elapsed_ms = sum(t.elapsed_time_ms for t in group)
first_start_time = min(t.start_time for t in group)
aggregate_timers.append(
(first_start_time, (k, total_elapsed_ms, num_calls)))
aggregate_timers.sort()
return zip(*aggregate_timers)[1] |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'spread'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'iterable'}, {'id': '5', 'type': 'block', 'children': ['6', '16', '24', '30', '60']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '13']}, {'id': '7', 'type': 'comparison_operator', 'children': ['8', '12'], 'value': '=='}; {'id': '8', 'type': 'call', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '10', 'type': 'argument_list', 'children': ['11']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'iterable'}; {'id': '12', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'return_statement', 'children': ['15']}, {'id': '15', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'iterable'}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'iterable'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '23', 'type': 'argument_list', 'children': []}; {'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': 'iterable'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'max_diff'}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '35', 'type': 'generator_expression', 'children': ['36', '42']}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'binary_operator', 'children': ['40', '41'], 'value': '-'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '42', 'type': 'for_in_clause', 'children': ['43', '46']}, {'id': '43', 'type': 'tuple_pattern', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '54']}, {'id': '49', 'type': 'subscript', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'iterable'}, {'id': '51', 'type': 'slice', 'children': ['52', '53']}; {'id': '52', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '53', 'type': 'colon', 'children': []}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'iterable'}; {'id': '56', 'type': 'slice', 'children': ['57', '58']}, {'id': '57', 'type': 'colon', 'children': []}; {'id': '58', 'type': 'unary_operator', 'children': ['59'], 'value': '-'}, {'id': '59', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '60', 'type': 'return_statement', 'children': ['61']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'max_diff'} | def spread(iterable):
if len(iterable) == 1:
return 0
iterable = iterable.copy()
iterable.sort()
max_diff = max(abs(i - j) for (i, j) in zip(iterable[1:], iterable[:-1]))
return max_diff |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_transcripts'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '36']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'txs'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '11', 'type': 'argument_list', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'transcripts'}, {'id': '15', 'type': 'keyword_argument', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '17', 'type': 'lambda', 'children': ['18', '20']}; {'id': '18', 'type': 'lambda_parameters', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '20', 'type': 'tuple', 'children': ['21', '26', '31']}, {'id': '21', 'type': 'attribute', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'chr'}; {'id': '26', 'type': 'attribute', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '31', 'type': 'attribute', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': '_transcripts'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'txs'} | def sort_transcripts(self):
txs = sorted(self.transcripts,key=lambda x: (x.range.chr, x.range.start, x.range.end))
self._transcripts = txs |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'in1d_events'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'ar1'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'ar2'}; {'id': '6', 'type': 'block', 'children': ['7', '16', '25', '39']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'ar1'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ascontiguousarray'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'ar1'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'ar2'}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'ascontiguousarray'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'ar2'}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'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_like'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'ar1'}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'uint8'}, {'id': '39', 'type': 'return_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'analysis_functions'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'get_in1d_sorted'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46', '47']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'ar1'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'ar2'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'tmp'} | def in1d_events(ar1, ar2):
ar1 = np.ascontiguousarray(ar1)
ar2 = np.ascontiguousarray(ar2)
tmp = np.empty_like(ar1, dtype=np.uint8)
return analysis_functions.get_in1d_sorted(ar1, ar2, tmp) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_by_priority'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'iterable'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'default_priority'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '10'}, {'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', '20']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'iterable'}, {'id': '17', 'type': 'keyword_argument', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '22', 'type': 'lambda', 'children': ['23', '25']}, {'id': '23', 'type': 'lambda_parameters', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'o'}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '29', '30']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'o'}, {'id': '29', 'type': 'string', 'children': [], 'value': "'priority'"} | def sort_by_priority(iterable, reverse=False, default_priority=10):
return sorted(iterable, reverse=reverse, key=lambda o: getattr(o, 'priority', default_priority)) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'apply'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'new_dtype'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'dictionary_splat_pattern', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'if_statement', 'children': ['16', '20', '47', '119']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'callable'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '20', 'type': 'block', 'children': ['21']}, {'id': '21', 'type': 'return_statement', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'Series'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '38', '41', '44']}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '31', '36']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'weld_type'}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'weld_type'}; {'id': '36', 'type': 'dictionary_splat', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '47', 'type': 'elif_clause', 'children': ['48', '53']}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '53', 'type': 'block', 'children': ['54', '60', '65', '74', '92', '103']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'check_type'}, {'id': '57', 'type': 'argument_list', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'mapping'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'check_dtype'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'new_dtype'}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'default_mapping'}; {'id': '68', 'type': 'dictionary', 'children': ['69']}, {'id': '69', 'type': 'pair', 'children': ['70', '71']}; {'id': '70', 'type': 'string', 'children': [], 'value': "'self'"}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '74', 'type': 'if_statement', 'children': ['75', '78', '83']}, {'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'is'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'mapping'}, {'id': '77', 'type': 'None', 'children': []}; {'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': 'mapping'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'default_mapping'}, {'id': '83', 'type': 'else_clause', 'children': ['84']}; {'id': '84', 'type': 'block', 'children': ['85']}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'mapping'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'default_mapping'}; {'id': '92', 'type': 'if_statement', 'children': ['93', '96']}, {'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': 'is'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'new_dtype'}, {'id': '95', 'type': 'None', 'children': []}; {'id': '96', 'type': 'block', 'children': ['97']}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'new_dtype'}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '103', 'type': 'return_statement', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'Series'}; {'id': '106', 'type': 'argument_list', 'children': ['107', '112', '115', '116']}, {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'weld_udf'}, {'id': '109', 'type': 'argument_list', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'new_dtype'}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '119', 'type': 'else_clause', 'children': ['120']}; {'id': '120', 'type': 'block', 'children': ['121']}, {'id': '121', 'type': 'raise_statement', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'string', 'children': [], 'value': "'Expected function or str defining a weld_template'"} | def apply(self, func, mapping=None, new_dtype=None, **kwargs):
if callable(func):
return Series(func(self.values,
weld_type=self.weld_type,
**kwargs),
self.index,
self.dtype,
self.name)
elif isinstance(func, str):
check_type(mapping, dict)
check_dtype(new_dtype)
default_mapping = {'self': self.values}
if mapping is None:
mapping = default_mapping
else:
mapping.update(default_mapping)
if new_dtype is None:
new_dtype = self.dtype
return Series(weld_udf(func,
mapping),
self.index,
new_dtype,
self.name)
else:
raise TypeError('Expected function or str defining a weld_template') |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'weld_sort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'arrays'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'weld_types'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'readable_text'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'ascending'}, {'id': '9', 'type': 'True', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '20', '28', '36', '46', '56', '68', '77', '88', '96']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'weld_obj_sort'}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': '_weld_sort'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18', '19']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'arrays'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'weld_types'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'weld_obj_struct'}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'weld_vec_of_struct_to_struct_of_vec'}, {'id': '25', 'type': 'argument_list', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'weld_obj_sort'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'weld_types'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'weld_obj_indices'}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'weld_select_from_struct'}, {'id': '33', 'type': 'argument_list', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'weld_obj_struct'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'intermediate_result'}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'LazyArrayResult'}, {'id': '41', 'type': 'argument_list', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'weld_obj_indices'}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'WeldLong'}, {'id': '45', 'type': 'argument_list', 'children': []}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'dependency_name'}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'Cache'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'cache_intermediate_result'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'intermediate_result'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'readable_text'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'fake_weld_input'}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'Cache'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'create_fake_array_input'}, {'id': '63', 'type': 'argument_list', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'dependency_name'}, {'id': '65', 'type': 'binary_operator', 'children': ['66', '67'], 'value': '+'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'readable_text'}, {'id': '67', 'type': 'string', 'children': [], 'value': "'_indices'"}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '73']}; {'id': '70', 'type': 'pattern_list', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'obj_id'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'weld_obj'}, {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'create_weld_object'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'fake_weld_input'}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'weld_obj'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'weld_code'}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'string', 'children': [], 'value': "'{}'"}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'obj_id'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'Cache'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'cache_fake_input'}, {'id': '93', 'type': 'argument_list', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'obj_id'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'fake_weld_input'}; {'id': '96', 'type': 'return_statement', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'weld_obj'} | def weld_sort(arrays, weld_types, readable_text, ascending=True):
weld_obj_sort = _weld_sort(arrays, weld_types, ascending)
weld_obj_struct = weld_vec_of_struct_to_struct_of_vec(weld_obj_sort, weld_types)
weld_obj_indices = weld_select_from_struct(weld_obj_struct, 0)
intermediate_result = LazyArrayResult(weld_obj_indices, WeldLong())
dependency_name = Cache.cache_intermediate_result(intermediate_result, readable_text)
fake_weld_input = Cache.create_fake_array_input(dependency_name, readable_text + '_indices')
obj_id, weld_obj = create_weld_object(fake_weld_input)
weld_obj.weld_code = '{}'.format(obj_id)
Cache.cache_fake_input(obj_id, fake_weld_input)
return weld_obj |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'chooseBestDuplicates'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'tped'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'oldSamples'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'completion'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'concordance_all'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '10', 'type': 'block', 'children': ['11', '15', '43', '56', '60', '88', '101', '105', '109', '435', '441', '447']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'chosenFile'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'try_statement', 'children': ['16', '27']}; {'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': 'chosenFile'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '26']}, {'id': '23', 'type': 'binary_operator', 'children': ['24', '25'], 'value': '+'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '25', 'type': 'string', 'children': [], 'value': '".chosen_samples.info"'}; {'id': '26', 'type': 'string', 'children': [], 'value': '"w"'}, {'id': '27', 'type': 'except_clause', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'IOError'}, {'id': '29', 'type': 'block', 'children': ['30', '38']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '%'}; {'id': '34', 'type': 'string', 'children': [], 'value': '"%(prefix)s.chosen_samples.info: can\'t write file"'}, {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'locals'}, {'id': '37', 'type': 'argument_list', 'children': []}; {'id': '38', 'type': 'raise_statement', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'ProgramError'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '43', 'type': 'print_statement', 'children': ['44', '46']}; {'id': '44', 'type': 'chevron', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'chosenFile'}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'string', 'children': [], 'value': '"\\t"'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'list', 'children': ['52', '53', '54', '55'], 'value': '["origIndex", "dupIndex", "famID", "indID"]'}; {'id': '52', 'type': 'string', 'children': [], 'value': '"origIndex"'}, {'id': '53', 'type': 'string', 'children': [], 'value': '"dupIndex"'}; {'id': '54', 'type': 'string', 'children': [], 'value': '"famID"'}, {'id': '55', 'type': 'string', 'children': [], 'value': '"indID"'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'excludedFile'}, {'id': '59', 'type': 'None', 'children': []}; {'id': '60', 'type': 'try_statement', 'children': ['61', '72']}, {'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': 'excludedFile'}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'open'}, {'id': '67', 'type': 'argument_list', 'children': ['68', '71']}; {'id': '68', 'type': 'binary_operator', 'children': ['69', '70'], 'value': '+'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '70', 'type': 'string', 'children': [], 'value': '".excluded_samples.info"'}, {'id': '71', 'type': 'string', 'children': [], 'value': '"w"'}; {'id': '72', 'type': 'except_clause', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'IOError'}; {'id': '74', 'type': 'block', 'children': ['75', '83']}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '78', 'type': 'binary_operator', 'children': ['79', '80'], 'value': '%'}, {'id': '79', 'type': 'string', 'children': [], 'value': '"%(prefix)s.excluded_samples.info: can\'t write file"'}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'locals'}; {'id': '82', 'type': 'argument_list', 'children': []}, {'id': '83', 'type': 'raise_statement', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'ProgramError'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '88', 'type': 'print_statement', 'children': ['89', '91']}, {'id': '89', 'type': 'chevron', 'children': ['90']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'excludedFile'}, {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'string', 'children': [], 'value': '"\\t"'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'list', 'children': ['97', '98', '99', '100'], 'value': '["origIndex", "dupIndex", "famID",\n "indID"]'}, {'id': '97', 'type': 'string', 'children': [], 'value': '"origIndex"'}; {'id': '98', 'type': 'string', 'children': [], 'value': '"dupIndex"'}, {'id': '99', 'type': 'string', 'children': [], 'value': '"famID"'}; {'id': '100', 'type': 'string', 'children': [], 'value': '"indID"'}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'chosenIndexes'}; {'id': '104', 'type': 'dictionary', 'children': []}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'sampleConcordance'}; {'id': '108', 'type': 'dictionary', 'children': []}, {'id': '109', 'type': 'for_statement', 'children': ['110', '113', '118']}; {'id': '110', 'type': 'pattern_list', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'indexes'}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'iteritems'}, {'id': '117', 'type': 'argument_list', 'children': []}; {'id': '118', 'type': 'block', 'children': ['119', '125', '134', '140', '154', '200', '209', '220', '229', '233', '237', '330', '349', '382', '427']}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'currCompletion'}; {'id': '122', 'type': 'subscript', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'completion'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'indexes'}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'sortedCompletionIndexes'}; {'id': '128', 'type': 'call', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'argsort'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'currCompletion'}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'concordance'}, {'id': '137', 'type': 'subscript', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'concordance_all'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'currConcordance'}, {'id': '143', 'type': 'list_comprehension', 'children': ['144', '145']}; {'id': '144', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '145', 'type': 'for_in_clause', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '147', 'type': 'call', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'xrange'}, {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'call', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'indexes'}; {'id': '154', 'type': 'for_statement', 'children': ['155', '156', '163']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '156', 'type': 'call', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'xrange'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}, {'id': '159', 'type': 'call', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'indexes'}, {'id': '163', 'type': 'block', 'children': ['164', '186']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'assignment', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'indexToKeep'}, {'id': '167', 'type': 'call', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'binary_operator', 'children': ['171', '181'], 'value': '-'}, {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'call', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '176', 'type': 'argument_list', 'children': ['177']}, {'id': '177', 'type': 'call', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '179', 'type': 'argument_list', 'children': ['180']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'indexes'}, {'id': '181', 'type': 'call', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '183', 'type': 'argument_list', 'children': ['184']}; {'id': '184', 'type': 'list', 'children': ['185'], 'value': '[i]'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}, {'id': '187', 'type': 'assignment', 'children': ['188', '191']}; {'id': '188', 'type': 'subscript', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'currConcordance'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '191', 'type': 'call', 'children': ['192', '195']}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'mean'}, {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'subscript', 'children': ['197', '198', '199']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'concordance'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'indexToKeep'}; {'id': '200', 'type': 'expression_statement', 'children': ['201']}, {'id': '201', 'type': 'assignment', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'currConcordance'}, {'id': '203', 'type': 'call', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '207', 'type': 'argument_list', 'children': ['208']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'currConcordance'}, {'id': '209', 'type': 'if_statement', 'children': ['210', '213']}; {'id': '210', 'type': 'comparison_operator', 'children': ['211', '212'], 'value': 'not'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'sampleConcordance'}, {'id': '213', 'type': 'block', 'children': ['214']}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}, {'id': '215', 'type': 'assignment', 'children': ['216', '219']}; {'id': '216', 'type': 'subscript', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'sampleConcordance'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'sample'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'currConcordance'}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}, {'id': '221', 'type': 'assignment', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'sortedConcordanceIndexes'}, {'id': '223', 'type': 'call', 'children': ['224', '227']}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'argsort'}, {'id': '227', 'type': 'argument_list', 'children': ['228']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'currConcordance'}, {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'assignment', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'nbToCheck'}; {'id': '232', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '233', 'type': 'expression_statement', 'children': ['234']}; {'id': '234', 'type': 'assignment', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'chosenIndex'}; {'id': '236', 'type': 'None', 'children': []}, {'id': '237', 'type': 'while_statement', 'children': ['238', '244']}; {'id': '238', 'type': 'comparison_operator', 'children': ['239', '240'], 'value': '<='}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'nbToCheck'}; {'id': '240', 'type': 'call', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '242', 'type': 'argument_list', 'children': ['243']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'indexes'}; {'id': '244', 'type': 'block', 'children': ['245', '256', '267', '283', '299', '305', '326']}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'assignment', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'completionValue'}; {'id': '248', 'type': 'subscript', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'currCompletion'}; {'id': '250', 'type': 'subscript', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'sortedCompletionIndexes'}; {'id': '252', 'type': 'binary_operator', 'children': ['253', '254'], 'value': '*'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'nbToCheck'}; {'id': '254', 'type': 'unary_operator', 'children': ['255'], 'value': '-'}, {'id': '255', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '256', 'type': 'expression_statement', 'children': ['257']}, {'id': '257', 'type': 'assignment', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'concordanceValue'}, {'id': '259', 'type': 'subscript', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'currConcordance'}, {'id': '261', 'type': 'subscript', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'sortedConcordanceIndexes'}, {'id': '263', 'type': 'binary_operator', 'children': ['264', '265'], 'value': '*'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'nbToCheck'}, {'id': '265', 'type': 'unary_operator', 'children': ['266'], 'value': '-'}; {'id': '266', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '267', 'type': 'expression_statement', 'children': ['268']}; {'id': '268', 'type': 'assignment', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'completionToConsider'}; {'id': '270', 'type': 'call', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '272', 'type': 'argument_list', 'children': ['273']}, {'id': '273', 'type': 'subscript', 'children': ['274', '282']}; {'id': '274', 'type': 'call', 'children': ['275', '278']}, {'id': '275', 'type': 'attribute', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'where'}; {'id': '278', 'type': 'argument_list', 'children': ['279']}, {'id': '279', 'type': 'comparison_operator', 'children': ['280', '281'], 'value': '>='}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'currCompletion'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'completionValue'}; {'id': '282', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '283', 'type': 'expression_statement', 'children': ['284']}; {'id': '284', 'type': 'assignment', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'concordanceToConsider'}; {'id': '286', 'type': 'call', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '288', 'type': 'argument_list', 'children': ['289']}, {'id': '289', 'type': 'subscript', 'children': ['290', '298']}; {'id': '290', 'type': 'call', 'children': ['291', '294']}, {'id': '291', 'type': 'attribute', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'where'}; {'id': '294', 'type': 'argument_list', 'children': ['295']}, {'id': '295', 'type': 'comparison_operator', 'children': ['296', '297'], 'value': '>='}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'currConcordance'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'concordanceValue'}; {'id': '298', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '299', 'type': 'expression_statement', 'children': ['300']}; {'id': '300', 'type': 'assignment', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'toConsider'}; {'id': '302', 'type': 'binary_operator', 'children': ['303', '304'], 'value': '&'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'concordanceToConsider'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'completionToConsider'}, {'id': '305', 'type': 'if_statement', 'children': ['306', '312']}; {'id': '306', 'type': 'comparison_operator', 'children': ['307', '311'], 'value': '>='}, {'id': '307', 'type': 'call', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '309', 'type': 'argument_list', 'children': ['310']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'toConsider'}, {'id': '311', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '312', 'type': 'block', 'children': ['313', '325']}, {'id': '313', 'type': 'expression_statement', 'children': ['314']}; {'id': '314', 'type': 'assignment', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'chosenIndex'}; {'id': '316', 'type': 'call', 'children': ['317', '320']}, {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'random'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'choice'}; {'id': '320', 'type': 'argument_list', 'children': ['321']}, {'id': '321', 'type': 'call', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '323', 'type': 'argument_list', 'children': ['324']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'toConsider'}, {'id': '325', 'type': 'break_statement', 'children': []}; {'id': '326', 'type': 'expression_statement', 'children': ['327']}, {'id': '327', 'type': 'augmented_assignment', 'children': ['328', '329'], 'value': '+='}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'nbToCheck'}, {'id': '329', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '330', 'type': 'if_statement', 'children': ['331', '334']}, {'id': '331', 'type': 'comparison_operator', 'children': ['332', '333'], 'value': 'is'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'chosenIndex'}, {'id': '333', 'type': 'None', 'children': []}; {'id': '334', 'type': 'block', 'children': ['335', '344']}, {'id': '335', 'type': 'expression_statement', 'children': ['336']}; {'id': '336', 'type': 'assignment', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '338', 'type': 'call', 'children': ['339', '342']}, {'id': '339', 'type': 'attribute', 'children': ['340', '341']}; {'id': '340', 'type': 'string', 'children': [], 'value': '"Could not choose the best sample ID for {}"'}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '342', 'type': 'argument_list', 'children': ['343']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '344', 'type': 'raise_statement', 'children': ['345']}, {'id': '345', 'type': 'call', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'ProgramError'}, {'id': '347', 'type': 'argument_list', 'children': ['348']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '349', 'type': 'print_statement', 'children': ['350', '352']}; {'id': '350', 'type': 'chevron', 'children': ['351']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'chosenFile'}; {'id': '352', 'type': 'call', 'children': ['353', '356']}, {'id': '353', 'type': 'attribute', 'children': ['354', '355']}; {'id': '354', 'type': 'string', 'children': [], 'value': '"\\t"'}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '356', 'type': 'argument_list', 'children': ['357']}, {'id': '357', 'type': 'list', 'children': ['358', '368', '376', '379'], 'value': '[str(oldSamples[sample][chosenIndex]+1),\n str(indexes[chosenIndex]+1), sample[0],\n sample[1]]'}; {'id': '358', 'type': 'call', 'children': ['359', '360']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '360', 'type': 'argument_list', 'children': ['361']}, {'id': '361', 'type': 'binary_operator', 'children': ['362', '367'], 'value': '+'}; {'id': '362', 'type': 'subscript', 'children': ['363', '366']}, {'id': '363', 'type': 'subscript', 'children': ['364', '365']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'oldSamples'}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'chosenIndex'}, {'id': '367', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '368', 'type': 'call', 'children': ['369', '370']}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '370', 'type': 'argument_list', 'children': ['371']}, {'id': '371', 'type': 'binary_operator', 'children': ['372', '375'], 'value': '+'}; {'id': '372', 'type': 'subscript', 'children': ['373', '374']}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'indexes'}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'chosenIndex'}, {'id': '375', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '376', 'type': 'subscript', 'children': ['377', '378']}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '378', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '379', 'type': 'subscript', 'children': ['380', '381']}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'sample'}, {'id': '381', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '382', 'type': 'for_statement', 'children': ['383', '386', '390']}, {'id': '383', 'type': 'pattern_list', 'children': ['384', '385']}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '386', 'type': 'call', 'children': ['387', '388']}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '388', 'type': 'argument_list', 'children': ['389']}, {'id': '389', 'type': 'identifier', 'children': [], 'value': 'indexes'}; {'id': '390', 'type': 'block', 'children': ['391']}, {'id': '391', 'type': 'if_statement', 'children': ['392', '395']}; {'id': '392', 'type': 'comparison_operator', 'children': ['393', '394'], 'value': '!='}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'chosenIndex'}, {'id': '395', 'type': 'block', 'children': ['396']}; {'id': '396', 'type': 'print_statement', 'children': ['397', '399']}, {'id': '397', 'type': 'chevron', 'children': ['398']}; {'id': '398', 'type': 'identifier', 'children': [], 'value': 'excludedFile'}, {'id': '399', 'type': 'call', 'children': ['400', '403']}; {'id': '400', 'type': 'attribute', 'children': ['401', '402']}, {'id': '401', 'type': 'string', 'children': [], 'value': '"\\t"'}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '403', 'type': 'argument_list', 'children': ['404']}; {'id': '404', 'type': 'list', 'children': ['405', '415', '421', '424'], 'value': '[str(oldSamples[sample][i]+1),\n str(index+1), sample[0],\n sample[1]]'}, {'id': '405', 'type': 'call', 'children': ['406', '407']}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '407', 'type': 'argument_list', 'children': ['408']}; {'id': '408', 'type': 'binary_operator', 'children': ['409', '414'], 'value': '+'}, {'id': '409', 'type': 'subscript', 'children': ['410', '413']}; {'id': '410', 'type': 'subscript', 'children': ['411', '412']}, {'id': '411', 'type': 'identifier', 'children': [], 'value': 'oldSamples'}; {'id': '412', 'type': 'identifier', 'children': [], 'value': 'sample'}, {'id': '413', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '414', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '415', 'type': 'call', 'children': ['416', '417']}; {'id': '416', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '417', 'type': 'argument_list', 'children': ['418']}; {'id': '418', 'type': 'binary_operator', 'children': ['419', '420'], 'value': '+'}, {'id': '419', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '420', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '421', 'type': 'subscript', 'children': ['422', '423']}; {'id': '422', 'type': 'identifier', 'children': [], 'value': 'sample'}, {'id': '423', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '424', 'type': 'subscript', 'children': ['425', '426']}, {'id': '425', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '426', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '427', 'type': 'expression_statement', 'children': ['428']}; {'id': '428', 'type': 'assignment', 'children': ['429', '432']}, {'id': '429', 'type': 'subscript', 'children': ['430', '431']}; {'id': '430', 'type': 'identifier', 'children': [], 'value': 'chosenIndexes'}, {'id': '431', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '432', 'type': 'subscript', 'children': ['433', '434']}, {'id': '433', 'type': 'identifier', 'children': [], 'value': 'indexes'}; {'id': '434', 'type': 'identifier', 'children': [], 'value': 'chosenIndex'}, {'id': '435', 'type': 'expression_statement', 'children': ['436']}; {'id': '436', 'type': 'call', 'children': ['437', '440']}, {'id': '437', 'type': 'attribute', 'children': ['438', '439']}; {'id': '438', 'type': 'identifier', 'children': [], 'value': 'chosenFile'}, {'id': '439', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '440', 'type': 'argument_list', 'children': []}, {'id': '441', 'type': 'expression_statement', 'children': ['442']}; {'id': '442', 'type': 'call', 'children': ['443', '446']}, {'id': '443', 'type': 'attribute', 'children': ['444', '445']}; {'id': '444', 'type': 'identifier', 'children': [], 'value': 'excludedFile'}, {'id': '445', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '446', 'type': 'argument_list', 'children': []}, {'id': '447', 'type': 'return_statement', 'children': ['448']}; {'id': '448', 'type': 'expression_list', 'children': ['449', '450', '451']}, {'id': '449', 'type': 'identifier', 'children': [], 'value': 'chosenIndexes'}; {'id': '450', 'type': 'identifier', 'children': [], 'value': 'completion'}, {'id': '451', 'type': 'identifier', 'children': [], 'value': 'sampleConcordance'} | def chooseBestDuplicates(tped, samples, oldSamples, completion,
concordance_all, prefix):
chosenFile = None
try:
chosenFile = open(prefix + ".chosen_samples.info", "w")
except IOError:
msg = "%(prefix)s.chosen_samples.info: can't write file" % locals()
raise ProgramError(msg)
print >>chosenFile, "\t".join(["origIndex", "dupIndex", "famID", "indID"])
excludedFile = None
try:
excludedFile = open(prefix + ".excluded_samples.info", "w")
except IOError:
msg = "%(prefix)s.excluded_samples.info: can't write file" % locals()
raise ProgramError(msg)
print >>excludedFile, "\t".join(["origIndex", "dupIndex", "famID",
"indID"])
chosenIndexes = {}
sampleConcordance = {}
for sample, indexes in samples.iteritems():
currCompletion = completion[indexes]
sortedCompletionIndexes = np.argsort(currCompletion)
concordance = concordance_all[sample]
currConcordance = [[] for i in xrange(len(indexes))]
for i in xrange(len(indexes)):
indexToKeep = list(set(range(len(indexes))) - set([i]))
currConcordance[i] = np.mean(concordance[i, indexToKeep])
currConcordance = np.array(currConcordance)
if sample not in sampleConcordance:
sampleConcordance[sample] = currConcordance
sortedConcordanceIndexes = np.argsort(currConcordance)
nbToCheck = 1
chosenIndex = None
while nbToCheck <= len(indexes):
completionValue = currCompletion[
sortedCompletionIndexes[nbToCheck*-1]
]
concordanceValue = currConcordance[
sortedConcordanceIndexes[nbToCheck*-1]
]
completionToConsider = set(
np.where(currCompletion >= completionValue)[0]
)
concordanceToConsider = set(
np.where(currConcordance >= concordanceValue)[0])
toConsider = concordanceToConsider & completionToConsider
if len(toConsider) >= 1:
chosenIndex = random.choice(list(toConsider))
break
nbToCheck += 1
if chosenIndex is None:
msg = "Could not choose the best sample ID for {}".format(sample)
raise ProgramError(msg)
print >>chosenFile, "\t".join([str(oldSamples[sample][chosenIndex]+1),
str(indexes[chosenIndex]+1), sample[0],
sample[1]])
for i, index in enumerate(indexes):
if i != chosenIndex:
print >>excludedFile, "\t".join([str(oldSamples[sample][i]+1),
str(index+1), sample[0],
sample[1]])
chosenIndexes[sample] = indexes[chosenIndex]
chosenFile.close()
excludedFile.close()
return chosenIndexes, completion, sampleConcordance |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'order_qc_dir'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dirnames'}, {'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': 'dirnames'}, {'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': 'dn'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'strptime'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '38']}, {'id': '21', 'type': 'subscript', 'children': ['22', '35']}; {'id': '22', 'type': 'call', 'children': ['23', '28']}, {'id': '23', 'type': 'attribute', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'dn'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'rstrip'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'string', 'children': [], 'value': '"/"'}, {'id': '35', 'type': 'slice', 'children': ['36', '37']}; {'id': '36', 'type': 'integer', 'children': [], 'value': '14'}, {'id': '37', 'type': 'colon', 'children': []} | def order_qc_dir(dirnames):
return sorted(
dirnames, key=lambda dn: time.strptime(
os.path.basename(dn.rstrip("/"))[14:],
"%Y-%m-%d_%H.%M.%S",
)
) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'fetch'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'webfonts'}; {'id': '6', 'type': 'block', 'children': ['7', '18']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sorted_keys'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'webfonts'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'for_statement', 'children': ['19', '20', '21']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'webfont_name'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'sorted_keys'}, {'id': '21', 'type': 'block', 'children': ['22']}; {'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': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'webfont_name'}, {'id': '29', 'type': 'subscript', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'webfonts'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'webfont_name'} | def fetch(self, webfonts):
sorted_keys = sorted(webfonts.keys())
for webfont_name in sorted_keys:
self.get(webfont_name, webfonts[webfont_name]) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_index'}, {'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': 'ascending'}, {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '23']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '17']}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'MultiIndex'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'raise_statement', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'string', 'children': [], 'value': "'Weld does not yet support sorting on multiple columns'"}, {'id': '23', 'type': 'return_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sort_values'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '36']}, {'id': '29', 'type': 'call', 'children': ['30', '35']}; {'id': '30', 'type': 'attribute', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': '_gather_names'}, {'id': '35', 'type': 'argument_list', 'children': []} | def sort_index(self, ascending=True):
if isinstance(self.index, MultiIndex):
raise NotImplementedError('Weld does not yet support sorting on multiple columns')
return self.sort_values(self.index._gather_names(), ascending) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_values'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '16', '21', '28', '41', '49', '55', '75', '86', '97', '107', '120', '131']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'check_type'}, {'id': '13', 'type': 'argument_list', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'ascending'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'check_str_or_list_str'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'by'}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'as_list'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '28', 'type': 'if_statement', 'children': ['29', '35']}, {'id': '29', 'type': 'comparison_operator', 'children': ['30', '34'], 'value': '>'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '34', 'type': 'integer', 'children': [], 'value': '1'}, {'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': 'NotImplementedError'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'string', 'children': [], 'value': "'Weld does not yet support sorting on multiple columns'"}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'all_data'}; {'id': '44', 'type': 'call', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'reset_index'}; {'id': '48', 'type': 'argument_list', 'children': []}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'by_data'}; {'id': '52', 'type': 'subscript', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'all_data'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'by'}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'sorted_indices'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'weld_sort'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '66', '71', '72']}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'by_data'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': '_gather_data_for_weld'}, {'id': '65', 'type': 'argument_list', 'children': []}; {'id': '66', 'type': 'call', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'by_data'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': '_gather_weld_types'}; {'id': '70', 'type': 'argument_list', 'children': []}, {'id': '71', 'type': 'string', 'children': [], 'value': "'sort_index'"}; {'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'ascending'}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'new_index'}; {'id': '78', 'type': 'call', 'children': ['79', '84']}, {'id': '79', 'type': 'attribute', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': '_iloc_indices'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'sorted_indices'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'new_columns'}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': '_iter'}; {'id': '96', 'type': 'argument_list', 'children': []}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'new_column_names'}; {'id': '100', 'type': 'list_comprehension', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'column'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '104', 'type': 'for_in_clause', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'new_columns'}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'new_columns'}; {'id': '110', 'type': 'list_comprehension', 'children': ['111', '117']}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': '_series_iloc'}, {'id': '113', 'type': 'argument_list', 'children': ['114', '115', '116']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'column'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'sorted_indices'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'new_index'}, {'id': '117', 'type': 'for_in_clause', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'column'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'new_columns'}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'new_data'}, {'id': '123', 'type': 'call', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}, {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '128', 'type': 'argument_list', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'new_column_names'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'new_columns'}, {'id': '131', 'type': 'return_statement', 'children': ['132']}; {'id': '132', 'type': 'call', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'DataFrame'}; {'id': '134', 'type': 'argument_list', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'new_data'} | def sort_values(self, by, ascending=True):
check_type(ascending, bool)
check_str_or_list_str(by)
by = as_list(by)
if len(by) > 1:
raise NotImplementedError('Weld does not yet support sorting on multiple columns')
all_data = self.reset_index()
by_data = all_data[by]
sorted_indices = weld_sort(by_data._gather_data_for_weld(),
by_data._gather_weld_types(),
'sort_index',
ascending=ascending)
new_index = self.index._iloc_indices(sorted_indices)
new_columns = list(self._iter())
new_column_names = [column.name for column in new_columns]
new_columns = [_series_iloc(column, sorted_indices, new_index) for column in new_columns]
new_data = OrderedDict(zip(new_column_names, new_columns))
return DataFrame(new_data, new_index) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'optimize_with_repeates'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'fast'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'n_times'}, {'id': '13', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'lambd'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'lambd_g'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'lambd_n'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'block', 'children': ['24', '33', '46', '50', '67', '223', '246', '260', '264', '282', '333']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'dlimix'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'getVerbose'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '33', 'type': 'if_statement', 'children': ['34', '38']}; {'id': '34', 'type': 'not_operator', 'children': ['35']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'init'}; {'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': 'self'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': '_initGP'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'fast'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'opt_list'}, {'id': '49', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'fixed0'}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'sp'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'zeros_like'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'subscript', 'children': ['59', '66']}, {'id': '59', 'type': 'call', 'children': ['60', '65']}; {'id': '60', 'type': 'attribute', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'gp'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'getParams'}, {'id': '65', 'type': 'argument_list', 'children': []}; {'id': '66', 'type': 'string', 'children': [], 'value': "'dataTerm'"}, {'id': '67', 'type': 'for_statement', 'children': ['68', '69', '73']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'n_times'}, {'id': '73', 'type': 'block', 'children': ['74', '82', '102', '128']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'scales1'}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': '_getScalesRand'}, {'id': '81', 'type': 'argument_list', 'children': []}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'fixed1'}, {'id': '85', 'type': 'binary_operator', 'children': ['86', '87'], 'value': '*'}; {'id': '86', 'type': 'float', 'children': [], 'value': '1e-1'}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'sp'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'randn'}, {'id': '91', 'type': 'argument_list', 'children': ['92', '97']}; {'id': '92', 'type': 'subscript', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'fixed0'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '97', 'type': 'subscript', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'fixed0'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '101', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'conv'}, {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'trainGP'}, {'id': '109', 'type': 'argument_list', 'children': ['110', '113', '116', '119', '122', '125']}; {'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'fast'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'fast'}, {'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'scales0'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'scales1'}; {'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'fixed0'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'fixed1'}, {'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'lambd'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'lambd'}; {'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'lambd_g'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'lambd_g'}, {'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'lambd_n'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'lambd_n'}; {'id': '128', 'type': 'if_statement', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'conv'}; {'id': '130', 'type': 'block', 'children': ['131', '135', '181']}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '134', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '135', 'type': 'for_statement', 'children': ['136', '137', '144']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'call', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'opt_list'}; {'id': '144', 'type': 'block', 'children': ['145']}, {'id': '145', 'type': 'if_statement', 'children': ['146', '167']}; {'id': '146', 'type': 'call', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'sp'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'allclose'}; {'id': '150', 'type': 'argument_list', 'children': ['151', '159']}, {'id': '151', 'type': 'call', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'abs'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'call', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'getScales'}; {'id': '158', 'type': 'argument_list', 'children': []}, {'id': '159', 'type': 'call', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'abs'}, {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'subscript', 'children': ['163', '166']}, {'id': '163', 'type': 'subscript', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'opt_list'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '166', 'type': 'string', 'children': [], 'value': "'scales'"}, {'id': '167', 'type': 'block', 'children': ['168', '172', '180']}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'temp'}, {'id': '171', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'augmented_assignment', 'children': ['174', '179'], 'value': '+='}; {'id': '174', 'type': 'subscript', 'children': ['175', '178']}, {'id': '175', 'type': 'subscript', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'opt_list'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '178', 'type': 'string', 'children': [], 'value': "'counter'"}, {'id': '179', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '180', 'type': 'break_statement', 'children': []}, {'id': '181', 'type': 'if_statement', 'children': ['182', '185']}; {'id': '182', 'type': 'comparison_operator', 'children': ['183', '184'], 'value': '=='}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '184', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '185', 'type': 'block', 'children': ['186', '190', '196', '206', '216']}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}, {'id': '187', 'type': 'assignment', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'opt'}, {'id': '189', 'type': 'dictionary', 'children': []}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'assignment', 'children': ['192', '195']}; {'id': '192', 'type': 'subscript', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'opt'}; {'id': '194', 'type': 'string', 'children': [], 'value': "'counter'"}, {'id': '195', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'assignment', 'children': ['198', '201']}; {'id': '198', 'type': 'subscript', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'opt'}; {'id': '200', 'type': 'string', 'children': [], 'value': "'LML'"}, {'id': '201', 'type': 'call', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'getLML'}, {'id': '205', 'type': 'argument_list', 'children': []}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}, {'id': '207', 'type': 'assignment', 'children': ['208', '211']}; {'id': '208', 'type': 'subscript', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'opt'}; {'id': '210', 'type': 'string', 'children': [], 'value': "'scales'"}, {'id': '211', 'type': 'call', 'children': ['212', '215']}; {'id': '212', 'type': 'attribute', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'getScales'}, {'id': '215', 'type': 'argument_list', 'children': []}; {'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': 'opt_list'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'opt'}, {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'assignment', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'LML'}; {'id': '226', 'type': 'call', 'children': ['227', '230']}, {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'sp'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '230', 'type': 'argument_list', 'children': ['231']}, {'id': '231', 'type': 'list_comprehension', 'children': ['232', '237']}; {'id': '232', 'type': 'subscript', 'children': ['233', '236']}, {'id': '233', 'type': 'subscript', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'opt_list'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '236', 'type': 'string', 'children': [], 'value': "'LML'"}, {'id': '237', 'type': 'for_in_clause', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '239', 'type': 'call', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'call', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '244', 'type': 'argument_list', 'children': ['245']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'opt_list'}; {'id': '246', 'type': 'expression_statement', 'children': ['247']}, {'id': '247', 'type': 'assignment', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '249', 'type': 'subscript', 'children': ['250', '255']}; {'id': '250', 'type': 'call', 'children': ['251', '254']}, {'id': '251', 'type': 'attribute', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'LML'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'argsort'}; {'id': '254', 'type': 'argument_list', 'children': []}, {'id': '255', 'type': 'slice', 'children': ['256', '257', '258']}; {'id': '256', 'type': 'colon', 'children': []}, {'id': '257', 'type': 'colon', 'children': []}; {'id': '258', 'type': 'unary_operator', 'children': ['259'], 'value': '-'}, {'id': '259', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '260', 'type': 'expression_statement', 'children': ['261']}, {'id': '261', 'type': 'assignment', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '263', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '264', 'type': 'if_statement', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '266', 'type': 'block', 'children': ['267', '272', '277']}, {'id': '267', 'type': 'expression_statement', 'children': ['268']}; {'id': '268', 'type': 'call', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '270', 'type': 'argument_list', 'children': ['271']}, {'id': '271', 'type': 'string', 'children': [], 'value': '"\\nLocal mimima\\n"'}; {'id': '272', 'type': 'expression_statement', 'children': ['273']}, {'id': '273', 'type': 'call', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '275', 'type': 'argument_list', 'children': ['276']}; {'id': '276', 'type': 'string', 'children': [], 'value': '"n_times\\t\\tLML"'}, {'id': '277', 'type': 'expression_statement', 'children': ['278']}; {'id': '278', 'type': 'call', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '280', 'type': 'argument_list', 'children': ['281']}, {'id': '281', 'type': 'string', 'children': [], 'value': '"------------------------------------"'}; {'id': '282', 'type': 'for_statement', 'children': ['283', '284', '291']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '284', 'type': 'call', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '286', 'type': 'argument_list', 'children': ['287']}, {'id': '287', 'type': 'call', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '289', 'type': 'argument_list', 'children': ['290']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'opt_list'}, {'id': '291', 'type': 'block', 'children': ['292', '303']}; {'id': '292', 'type': 'expression_statement', 'children': ['293']}, {'id': '293', 'type': 'call', 'children': ['294', '297']}; {'id': '294', 'type': 'attribute', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '297', 'type': 'argument_list', 'children': ['298']}; {'id': '298', 'type': 'subscript', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'opt_list'}; {'id': '300', 'type': 'subscript', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '303', 'type': 'if_statement', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '305', 'type': 'block', 'children': ['306', '328']}; {'id': '306', 'type': 'expression_statement', 'children': ['307']}, {'id': '307', 'type': 'call', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '309', 'type': 'argument_list', 'children': ['310']}; {'id': '310', 'type': 'parenthesized_expression', 'children': ['311'], 'value': '()'}, {'id': '311', 'type': 'binary_operator', 'children': ['312', '313'], 'value': '%'}; {'id': '312', 'type': 'string', 'children': [], 'value': '"%d\\t\\t%f"'}, {'id': '313', 'type': 'tuple', 'children': ['314', '321']}; {'id': '314', 'type': 'subscript', 'children': ['315', '320']}, {'id': '315', 'type': 'subscript', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'opt_list'}, {'id': '317', 'type': 'subscript', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '320', 'type': 'string', 'children': [], 'value': "'counter'"}, {'id': '321', 'type': 'subscript', 'children': ['322', '327']}; {'id': '322', 'type': 'subscript', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'opt_list'}; {'id': '324', 'type': 'subscript', 'children': ['325', '326']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '327', 'type': 'string', 'children': [], 'value': "'LML'"}; {'id': '328', 'type': 'expression_statement', 'children': ['329']}, {'id': '329', 'type': 'call', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '331', 'type': 'argument_list', 'children': ['332']}; {'id': '332', 'type': 'string', 'children': [], 'value': '""'}, {'id': '333', 'type': 'return_statement', 'children': ['334']} | def optimize_with_repeates(self,fast=None,verbose=None,n_times=10,lambd=None,lambd_g=None,lambd_n=None):
verbose = dlimix.getVerbose(verbose)
if not self.init: self._initGP(fast)
opt_list = []
fixed0 = sp.zeros_like(self.gp.getParams()['dataTerm'])
for i in range(n_times):
scales1 = self._getScalesRand()
fixed1 = 1e-1*sp.randn(fixed0.shape[0],fixed0.shape[1])
conv = self.trainGP(fast=fast,scales0=scales1,fixed0=fixed1,lambd=lambd,lambd_g=lambd_g,lambd_n=lambd_n)
if conv:
temp=1
for j in range(len(opt_list)):
if sp.allclose(abs(self.getScales()),abs(opt_list[j]['scales'])):
temp=0
opt_list[j]['counter']+=1
break
if temp==1:
opt = {}
opt['counter'] = 1
opt['LML'] = self.getLML()
opt['scales'] = self.getScales()
opt_list.append(opt)
LML = sp.array([opt_list[i]['LML'] for i in range(len(opt_list))])
index = LML.argsort()[::-1]
out = []
if verbose:
print("\nLocal mimima\n")
print("n_times\t\tLML")
print("------------------------------------")
for i in range(len(opt_list)):
out.append(opt_list[index[i]])
if verbose:
print(("%d\t\t%f" % (opt_list[index[i]]['counter'], opt_list[index[i]]['LML'])))
print("")
return out |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_prefixes'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'orig'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'prefixes'}, {'id': '7', 'type': 'string', 'children': [], 'value': "'@+'"}; {'id': '8', 'type': 'block', 'children': ['9', '13', '26']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '12', 'type': 'string', 'children': [], 'value': "''"}, {'id': '13', 'type': 'for_statement', 'children': ['14', '15', '16']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'prefixes'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'if_statement', 'children': ['18', '21']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'in'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'orig'}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'augmented_assignment', 'children': ['24', '25'], 'value': '+='}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'new'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '26', 'type': 'return_statement', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'new'} | def sort_prefixes(orig, prefixes='@+'):
new = ''
for prefix in prefixes:
if prefix in orig:
new += prefix
return new |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_children'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'attribute'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'reverse_order'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '16', '113', '119', '133']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'sorted_children'}, {'id': '15', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '16', 'type': 'if_statement', 'children': ['17', '18', '88']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'attribute'}; {'id': '18', 'type': 'block', 'children': ['19', '23', '27', '57', '81']}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'sortable_children'}; {'id': '22', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'unsortable_children'}; {'id': '26', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '27', 'type': 'for_statement', 'children': ['28', '29', '32']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': '__children'}; {'id': '32', 'type': 'block', 'children': ['33']}, {'id': '33', 'type': 'if_statement', 'children': ['34', '40', '48']}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'attribute_exists'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'attribute'}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'sortable_children'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '48', 'type': 'else_clause', 'children': ['49']}, {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'unsortable_children'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'sorted_children'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '64', '76']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'sortable_children'}; {'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '66', 'type': 'lambda', 'children': ['67', '69']}, {'id': '67', 'type': 'lambda_parameters', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '69', 'type': 'attribute', 'children': ['70', '75']}; {'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': 'x'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'attribute'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '78', 'type': 'boolean_operator', 'children': ['79', '80'], 'value': 'or'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'reverse_order'}; {'id': '80', 'type': 'False', 'children': []}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'sorted_children'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'unsortable_children'}; {'id': '88', 'type': 'else_clause', 'children': ['89']}, {'id': '89', 'type': 'block', 'children': ['90']}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'sorted_children'}, {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '95', 'type': 'argument_list', 'children': ['96', '99', '108']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '101', 'type': 'lambda', 'children': ['102', '104']}; {'id': '102', 'type': 'lambda_parameters', 'children': ['103']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '104', 'type': 'parenthesized_expression', 'children': ['105'], 'value': '()'}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '110', 'type': 'boolean_operator', 'children': ['111', '112'], 'value': 'or'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'reverse_order'}; {'id': '112', 'type': 'False', 'children': []}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': '__children'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'sorted_children'}, {'id': '119', 'type': 'for_statement', 'children': ['120', '121', '124']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': '__children'}; {'id': '124', 'type': 'block', 'children': ['125']}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'sort_children'}; {'id': '130', 'type': 'argument_list', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'attribute'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'reverse_order'}, {'id': '133', 'type': 'return_statement', 'children': ['134']} | def sort_children(self, attribute=None, reverse_order=False):
sorted_children = []
if attribute:
sortable_children = []
unsortable_children = []
for child in self.__children:
if child.attribute_exists(attribute):
sortable_children.append(child)
else:
unsortable_children.append(child)
sorted_children = sorted(sortable_children, key=lambda x: getattr(
x, attribute).value, reverse=reverse_order or False)
sorted_children.extend(unsortable_children)
else:
sorted_children = sorted(self.children, key=lambda x: (x.name), reverse=reverse_order or False)
self.__children = sorted_children
for child in self.__children:
child.sort_children(attribute, reverse_order)
return True |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort_kw_matches'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'skw_matches'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '7', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '8', 'type': 'block', 'children': ['9', '20', '31']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sorted_keywords'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'skw_matches'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '19', 'type': 'argument_list', 'children': []}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'sorted_keywords'}, {'id': '25', 'type': 'keyword_argument', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'cmp_to_key'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': '_skw_matches_comparator'}, {'id': '31', 'type': 'return_statement', 'children': ['32']}; {'id': '32', 'type': 'boolean_operator', 'children': ['33', '40'], 'value': 'or'}, {'id': '33', 'type': 'boolean_operator', 'children': ['34', '35'], 'value': 'and'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '35', 'type': 'subscript', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'sorted_keywords'}, {'id': '37', 'type': 'slice', 'children': ['38', '39']}; {'id': '38', 'type': 'colon', 'children': []}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'limit'} | def _sort_kw_matches(skw_matches, limit=0):
sorted_keywords = list(skw_matches.items())
sorted(sorted_keywords, key=cmp_to_key(_skw_matches_comparator))
return limit and sorted_keywords[:limit] or sorted_keywords |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'trim'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'n_peaks'}; {'id': '6', 'type': 'block', 'children': ['7', '13']}, {'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': 'sortByIntensity'}; {'id': '12', 'type': 'argument_list', 'children': []}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'ims'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'spectrum_trim'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'ptr'} | def trim(self, n_peaks):
self.sortByIntensity()
ims.spectrum_trim(self.ptr, n_peaks) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'centroids'}, {'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': 'window_size'}, {'id': '7', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '8', 'type': 'block', 'children': ['9', '15', '25', '35', '41', '60']}, {'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': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sortByMass'}; {'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': 'mzs'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': '_cffi_buffer'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'masses'}; {'id': '24', 'type': 'string', 'children': [], 'value': "'d'"}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'intensities'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': '_cffi_buffer'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'intensities'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'f'"}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'size'}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '44', 'type': 'call', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'ims'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'spectrum_new_from_raw'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '50', '53', '56']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'mzs'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'ptr'}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'intensities'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'ptr'}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'window_size'}; {'id': '60', 'type': 'return_statement', 'children': ['61']}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': '_new_spectrum'}, {'id': '63', 'type': 'argument_list', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'CentroidedSpectrum'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'p'} | def centroids(self, window_size=5):
self.sortByMass()
mzs = _cffi_buffer(self.masses, 'd')
intensities = _cffi_buffer(self.intensities, 'f')
n = self.size
p = ims.spectrum_new_from_raw(n, mzs.ptr, intensities.ptr, int(window_size))
return _new_spectrum(CentroidedSpectrum, p) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_engines_by_priority'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'engines'}; {'id': '6', 'type': 'None', 'children': []}, {'id': '7', 'type': 'block', 'children': ['8', '17']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '12']}, {'id': '9', 'type': 'comparison_operator', 'children': ['10', '11'], 'value': 'is'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'engines'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'engines'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'ENGINES'}, {'id': '17', 'type': 'return_statement', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'engines'}; {'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'operator'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'methodcaller'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'string', 'children': [], 'value': '"priority"'} | def list_engines_by_priority(engines=None):
if engines is None:
engines = ENGINES
return sorted(engines, key=operator.methodcaller("priority")) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'union'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dict1'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'dict2'}; {'id': '6', 'type': 'block', 'children': ['7', '48']}, {'id': '7', 'type': 'for_statement', 'children': ['8', '11', '16']}; {'id': '8', 'type': 'pattern_list', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'dict2'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'if_statement', 'children': ['18', '27', '40']}; {'id': '18', 'type': 'boolean_operator', 'children': ['19', '22'], 'value': 'and'}, {'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'in'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'dict1'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '33']}; {'id': '30', 'type': 'subscript', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'dict1'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'union'}, {'id': '35', 'type': 'argument_list', 'children': ['36', '39']}; {'id': '36', 'type': 'subscript', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'dict1'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '40', 'type': 'else_clause', 'children': ['41']}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '47']}; {'id': '44', 'type': 'subscript', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'dict1'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '48', 'type': 'return_statement', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'dict1'} | def union(dict1, dict2):
for key, value in dict2.items():
if key in dict1 and isinstance(value, dict):
dict1[key] = union(dict1[key], value)
else:
dict1[key] = value
return dict1 |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_format_data'}, {'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': 'list_comprehension', 'children': ['9', '10', '37']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'spectrum'}; {'id': '10', 'type': 'for_in_clause', 'children': ['11', '12', '13']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'spectrum'}; {'id': '12', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '15', 'type': 'argument_list', 'children': ['16', '27']}; {'id': '16', 'type': 'conditional_expression', 'children': ['17', '18', '25'], 'value': 'if'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '22', 'type': 'tuple', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '25', 'type': 'list', 'children': ['26'], 'value': '[data]'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '29', 'type': 'lambda', 'children': ['30', '32']}; {'id': '30', 'type': 'lambda_parameters', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '32', 'type': 'subscript', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'disp'}; {'id': '36', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '37', 'type': 'if_clause', 'children': ['38']}; {'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': 'any'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'isfinite'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'spectrum'} | def _format_data(self, data):
return [spectrum for spectrum in \
sorted(data if isinstance(data, (list, tuple)) else [data],
key=lambda x: x.disp[0]) if np.any(np.isfinite(spectrum.flux))] |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_sorting'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'resources'}; {'id': '8', 'type': 'block', 'children': ['9', '13', '21', '31']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sorting'}; {'id': '12', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '13', 'type': 'if_statement', 'children': ['14', '18']}; {'id': '14', 'type': 'not_operator', 'children': ['15']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'GET'}; {'id': '18', 'type': 'block', 'children': ['19']}, {'id': '19', 'type': 'return_statement', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'sorting'}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '24', 'type': 'binary_operator', 'children': ['25', '30'], 'value': '+'}, {'id': '25', 'type': 'attribute', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': '_meta'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'dyn_prefix'}; {'id': '30', 'type': 'string', 'children': [], 'value': "'sort'"}, {'id': '31', 'type': 'return_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '38']}, {'id': '33', 'type': 'attribute', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'GET'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'getlist'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'prefix'} | def get_sorting(self, request, **resources):
sorting = []
if not request.GET:
return sorting
prefix = self._meta.dyn_prefix + 'sort'
return request.GET.getlist(prefix) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'list_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort_tuples'}, {'id': '7', 'type': 'block', 'children': ['8', '10', '14', '72']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'string', 'children': [], 'value': "''' pymongo-style sorting. Accepts a list of tuples.\n :param sort_tuples: varargs of sort tuples.\n '''"}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'for_statement', 'children': ['15', '18', '19']}, {'id': '15', 'type': 'pattern_list', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'direction'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'sort_tuples'}, {'id': '19', 'type': 'block', 'children': ['20', '30']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'resolve_name'}, {'id': '25', 'type': 'argument_list', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '30', 'type': 'if_statement', 'children': ['31', '36', '46', '63']}, {'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'in'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'direction'}, {'id': '33', 'type': 'tuple', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'ASCENDING'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'query'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '46', 'type': 'elif_clause', 'children': ['47', '53']}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'in'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'direction'}, {'id': '49', 'type': 'tuple', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'DESCENDING'}, {'id': '51', 'type': 'unary_operator', 'children': ['52'], 'value': '-'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'descending'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '63', 'type': 'else_clause', 'children': ['64']}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'raise_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'BadQueryException'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'binary_operator', 'children': ['70', '71'], 'value': '%'}; {'id': '70', 'type': 'string', 'children': [], 'value': "'Bad sort direction: %s'"}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'direction'}; {'id': '72', 'type': 'return_statement', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'query'} | def sort(self, *sort_tuples):
''' pymongo-style sorting. Accepts a list of tuples.
:param sort_tuples: varargs of sort tuples.
'''
query = self
for name, direction in sort_tuples:
field = resolve_name(self.type, name)
if direction in (ASCENDING, 1):
query = query.ascending(field)
elif direction in (DESCENDING, -1):
query = query.descending(field)
else:
raise BadQueryException('Bad sort direction: %s' % direction)
return query |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_has_bad_coords'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'stream'}; {'id': '6', 'type': 'block', 'children': ['7', '14', '29', '38', '55']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '11']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': '=='}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'stream'}; {'id': '10', 'type': 'string', 'children': [], 'value': '"com.dc3/dc3.broker"'}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'return_statement', 'children': ['13']}, {'id': '13', 'type': 'True', 'children': []}; {'id': '14', 'type': 'if_statement', 'children': ['15', '26']}, {'id': '15', 'type': 'not_operator', 'children': ['16']}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '25'], 'value': '=='}, {'id': '17', 'type': 'subscript', 'children': ['18', '24']}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'stream'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '24', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '25', 'type': 'string', 'children': [], 'value': "'nasa.gsfc.gcn'"}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'return_statement', 'children': ['28']}; {'id': '28', 'type': 'False', 'children': []}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'toplevel_params'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'vp'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'get_toplevel_params'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '38', 'type': 'if_statement', 'children': ['39', '42']}, {'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'in'}; {'id': '40', 'type': 'string', 'children': [], 'value': '"Coords_String"'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'toplevel_params'}; {'id': '42', 'type': 'block', 'children': ['43']}, {'id': '43', 'type': 'if_statement', 'children': ['44', '52']}; {'id': '44', 'type': 'parenthesized_expression', 'children': ['45'], 'value': '()'}, {'id': '45', 'type': 'comparison_operator', 'children': ['46', '51'], 'value': '=='}; {'id': '46', 'type': 'subscript', 'children': ['47', '50']}, {'id': '47', 'type': 'subscript', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'toplevel_params'}, {'id': '49', 'type': 'string', 'children': [], 'value': '"Coords_String"'}; {'id': '50', 'type': 'string', 'children': [], 'value': "'value'"}, {'id': '51', 'type': 'string', 'children': [], 'value': '"unavailable/inappropriate"'}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'return_statement', 'children': ['54']}; {'id': '54', 'type': 'True', 'children': []}, {'id': '55', 'type': 'return_statement', 'children': ['56']} | def _has_bad_coords(root, stream):
if stream == "com.dc3/dc3.broker":
return True
if not stream.split('/')[0] == 'nasa.gsfc.gcn':
return False
toplevel_params = vp.get_toplevel_params(root)
if "Coords_String" in toplevel_params:
if (toplevel_params["Coords_String"]['value'] ==
"unavailable/inappropriate"):
return True
return False |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19', '31']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_chain'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '7']}, {'id': '5', 'type': 'list_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'ranges'}, {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'generic_type', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'Iterable'}; {'id': '10', 'type': 'type_parameter', 'children': ['11']}, {'id': '11', 'type': 'type', 'children': ['12']}; {'id': '12', 'type': 'generic_type', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'Tuple'}; {'id': '14', 'type': 'type_parameter', 'children': ['15', '17']}, {'id': '15', 'type': 'type', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '17', 'type': 'type', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '19', 'type': 'type', 'children': ['20']}; {'id': '20', 'type': 'generic_type', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'List'}; {'id': '22', 'type': 'type_parameter', 'children': ['23']}, {'id': '23', 'type': 'type', 'children': ['24']}; {'id': '24', 'type': 'generic_type', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'Tuple'}; {'id': '26', 'type': 'type_parameter', 'children': ['27', '29']}, {'id': '27', 'type': 'type', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '29', 'type': 'type', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'return_statement', 'children': ['33']}, {'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': 'itertools'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'chain'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'list_splat', 'children': ['42']} | def sorted_chain(*ranges: Iterable[Tuple[int, int]]) -> List[Tuple[int, int]]:
return sorted(itertools.chain(*ranges)) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'partition_range'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'annotations'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '15', '19', '27', '127']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '12', 'type': 'boolean_operator', 'children': ['13', '14'], 'value': 'or'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'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': 'partitioning'}; {'id': '18', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '24']}, {'id': '21', 'type': 'pattern_list', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'part_start'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'part_levels'}; {'id': '24', 'type': 'expression_list', 'children': ['25', '26']}, {'id': '25', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '26', 'type': 'None', 'children': []}, {'id': '27', 'type': 'for_statement', 'children': ['28', '29', '51']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'set'}; {'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': 'itertools'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'chain'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '43']}; {'id': '40', 'type': 'list', 'children': ['41', '42'], 'value': '[0, stop]'}, {'id': '41', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '43', 'type': 'list_splat', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'itertools'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'chain'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'list_splat', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'annotations'}, {'id': '51', 'type': 'block', 'children': ['52', '68', '94', '104']}; {'id': '52', 'type': 'if_statement', 'children': ['53', '56']}, {'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': '=='}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '56', 'type': 'block', 'children': ['57', '67']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'partitioning'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'tuple', 'children': ['64', '65', '66']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'part_start'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'part_levels'}, {'id': '67', 'type': 'break_statement', 'children': []}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'levels'}, {'id': '71', 'type': 'set_comprehension', 'children': ['72', '73', '81']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'level'}, {'id': '73', 'type': 'for_in_clause', 'children': ['74', '77']}; {'id': '74', 'type': 'pattern_list', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'regions'}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'annotations'}, {'id': '81', 'type': 'if_clause', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '84', 'type': 'generator_expression', 'children': ['85', '89']}, {'id': '85', 'type': 'comparison_operator', 'children': ['86', '87', '88'], 'value': '<='}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '89', 'type': 'for_in_clause', 'children': ['90', '93']}; {'id': '90', 'type': 'pattern_list', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'regions'}; {'id': '94', 'type': 'if_statement', 'children': ['95', '98']}, {'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': '=='}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '97', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '98', 'type': 'block', 'children': ['99', '103']}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'part_levels'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'levels'}, {'id': '103', 'type': 'continue_statement', 'children': []}; {'id': '104', 'type': 'if_statement', 'children': ['105', '108']}, {'id': '105', 'type': 'comparison_operator', 'children': ['106', '107'], 'value': '!='}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'levels'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'part_levels'}; {'id': '108', 'type': 'block', 'children': ['109', '119']}, {'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': 'partitioning'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'tuple', 'children': ['116', '117', '118']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'part_start'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'part_levels'}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '124']}, {'id': '121', 'type': 'pattern_list', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'part_start'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'part_levels'}; {'id': '124', 'type': 'expression_list', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'levels'}, {'id': '127', 'type': 'return_statement', 'children': ['128']} | def partition_range(stop, annotations=None):
annotations = annotations or []
partitioning = []
part_start, part_levels = 0, None
for p in sorted(set(itertools.chain([0, stop],
*itertools.chain(*annotations)))):
if p == stop:
partitioning.append( (part_start, p, part_levels) )
break
levels = {level for level, regions in enumerate(annotations)
if any(x <= p < y for x, y in regions)}
if p == 0:
part_levels = levels
continue
if levels != part_levels:
partitioning.append( (part_start, p, part_levels) )
part_start, part_levels = p, levels
return partitioning |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'pprint_sequence'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'sequence'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'annotations'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'block_length'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '10'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'blocks_per_line'}, {'id': '13', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'PlaintextFormat'}, {'id': '17', 'type': 'block', 'children': ['18', '24', '35', '71', '95', '271']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'annotations'}, {'id': '21', 'type': 'boolean_operator', 'children': ['22', '23'], 'value': 'or'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'annotations'}, {'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': 'partitioning'}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'partition_range'}, {'id': '29', 'type': 'argument_list', 'children': ['30', '34']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'annotations'}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'margin'}; {'id': '38', 'type': 'binary_operator', 'children': ['39', '63'], 'value': '+'}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'binary_operator', 'children': ['43', '62'], 'value': '+'}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'math'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'floor'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'math'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '61']}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '55', 'type': 'argument_list', 'children': ['56', '60']}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '60', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '61', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '62', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'subscript', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'margin'}; {'id': '70', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '74', 'type': 'binary_operator', 'children': ['75', '94'], 'value': '+'}, {'id': '75', 'type': 'binary_operator', 'children': ['76', '89'], 'value': '+'}; {'id': '76', 'type': 'call', 'children': ['77', '87']}, {'id': '77', 'type': 'attribute', 'children': ['78', '86']}; {'id': '78', 'type': 'parenthesized_expression', 'children': ['79'], 'value': '()'}, {'id': '79', 'type': 'binary_operator', 'children': ['80', '85'], 'value': '+'}; {'id': '80', 'type': 'subscript', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'margin'}; {'id': '84', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '85', 'type': 'string', 'children': [], 'value': "'1'"}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'rjust'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'margin'}, {'id': '89', 'type': 'subscript', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'margin'}, {'id': '93', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '94', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '95', 'type': 'for_statement', 'children': ['96', '97', '106']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '99', 'type': 'argument_list', 'children': ['100', '101', '105']}; {'id': '100', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'sequence'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'block_length'}; {'id': '106', 'type': 'block', 'children': ['107', '141', '145', '215']}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '110', 'type': 'list_comprehension', 'children': ['111', '125', '131']}, {'id': '111', 'type': 'tuple', 'children': ['112', '117', '124']}; {'id': '112', 'type': 'call', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '114', 'type': 'argument_list', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '119', 'type': 'argument_list', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '121', 'type': 'binary_operator', 'children': ['122', '123'], 'value': '+'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'block_length'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'levels'}, {'id': '125', 'type': 'for_in_clause', 'children': ['126', '130']}; {'id': '126', 'type': 'pattern_list', 'children': ['127', '128', '129']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'levels'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'partitioning'}, {'id': '131', 'type': 'if_clause', 'children': ['132']}; {'id': '132', 'type': 'boolean_operator', 'children': ['133', '138'], 'value': 'and'}, {'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': '<'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '135', 'type': 'binary_operator', 'children': ['136', '137'], 'value': '+'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'block_length'}; {'id': '138', 'type': 'comparison_operator', 'children': ['139', '140'], 'value': '>'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'augmented_assignment', 'children': ['143', '144'], 'value': '+='}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '144', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '145', 'type': 'for_statement', 'children': ['146', '150', '151']}; {'id': '146', 'type': 'pattern_list', 'children': ['147', '148', '149']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'levels'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'block'}, {'id': '151', 'type': 'block', 'children': ['152', '175']}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'delimiters'}, {'id': '155', 'type': 'list_comprehension', 'children': ['156', '159', '171']}; {'id': '156', 'type': 'tuple', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'left'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'right'}, {'id': '159', 'type': 'for_in_clause', 'children': ['160', '165']}; {'id': '160', 'type': 'pattern_list', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '162', 'type': 'tuple_pattern', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'left'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'right'}, {'id': '165', 'type': 'call', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'annotations'}, {'id': '171', 'type': 'if_clause', 'children': ['172']}; {'id': '172', 'type': 'comparison_operator', 'children': ['173', '174'], 'value': 'in'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'levels'}, {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'augmented_assignment', 'children': ['177', '178'], 'value': '+='}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '178', 'type': 'parenthesized_expression', 'children': ['179'], 'value': '()'}, {'id': '179', 'type': 'binary_operator', 'children': ['180', '204'], 'value': '+'}; {'id': '180', 'type': 'binary_operator', 'children': ['181', '195'], 'value': '+'}, {'id': '181', 'type': 'call', 'children': ['182', '185']}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}, {'id': '183', 'type': 'string', 'children': [], 'value': "''"}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '185', 'type': 'generator_expression', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'left'}, {'id': '187', 'type': 'for_in_clause', 'children': ['188', '191']}; {'id': '188', 'type': 'pattern_list', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'left'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'right'}, {'id': '191', 'type': 'call', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'reversed'}, {'id': '193', 'type': 'argument_list', 'children': ['194']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'delimiters'}, {'id': '195', 'type': 'call', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'subscript', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '200', 'type': 'slice', 'children': ['201', '202', '203']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '202', 'type': 'colon', 'children': []}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '204', 'type': 'call', 'children': ['205', '208']}, {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'string', 'children': [], 'value': "''"}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '208', 'type': 'generator_expression', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'right'}; {'id': '210', 'type': 'for_in_clause', 'children': ['211', '214']}, {'id': '211', 'type': 'pattern_list', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'left'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'right'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'delimiters'}, {'id': '215', 'type': 'if_statement', 'children': ['216', '236']}; {'id': '216', 'type': 'parenthesized_expression', 'children': ['217'], 'value': '()'}, {'id': '217', 'type': 'boolean_operator', 'children': ['218', '228'], 'value': 'and'}; {'id': '218', 'type': 'not_operator', 'children': ['219']}, {'id': '219', 'type': 'binary_operator', 'children': ['220', '224'], 'value': '%'}; {'id': '220', 'type': 'parenthesized_expression', 'children': ['221'], 'value': '()'}, {'id': '221', 'type': 'binary_operator', 'children': ['222', '223'], 'value': '+'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'block_length'}; {'id': '224', 'type': 'parenthesized_expression', 'children': ['225'], 'value': '()'}, {'id': '225', 'type': 'binary_operator', 'children': ['226', '227'], 'value': '*'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'block_length'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'blocks_per_line'}; {'id': '228', 'type': 'comparison_operator', 'children': ['229', '232'], 'value': '<'}, {'id': '229', 'type': 'binary_operator', 'children': ['230', '231'], 'value': '+'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'block_length'}; {'id': '232', 'type': 'call', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '234', 'type': 'argument_list', 'children': ['235']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '236', 'type': 'block', 'children': ['237']}, {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'augmented_assignment', 'children': ['239', '240'], 'value': '+='}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '240', 'type': 'parenthesized_expression', 'children': ['241'], 'value': '()'}, {'id': '241', 'type': 'binary_operator', 'children': ['242', '270'], 'value': '+'}; {'id': '242', 'type': 'binary_operator', 'children': ['243', '265'], 'value': '+'}, {'id': '243', 'type': 'binary_operator', 'children': ['244', '245'], 'value': '+'}; {'id': '244', 'type': 'string', 'children': [], 'value': "'\\n'"}, {'id': '245', 'type': 'call', 'children': ['246', '263']}; {'id': '246', 'type': 'attribute', 'children': ['247', '262']}, {'id': '247', 'type': 'parenthesized_expression', 'children': ['248'], 'value': '()'}; {'id': '248', 'type': 'binary_operator', 'children': ['249', '254'], 'value': '+'}, {'id': '249', 'type': 'subscript', 'children': ['250', '253']}; {'id': '250', 'type': 'attribute', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'margin'}, {'id': '253', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '254', 'type': 'call', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '256', 'type': 'argument_list', 'children': ['257']}, {'id': '257', 'type': 'binary_operator', 'children': ['258', '261'], 'value': '+'}; {'id': '258', 'type': 'binary_operator', 'children': ['259', '260'], 'value': '+'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'block_length'}, {'id': '261', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'rjust'}, {'id': '263', 'type': 'argument_list', 'children': ['264']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'margin'}, {'id': '265', 'type': 'subscript', 'children': ['266', '269']}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'margin'}, {'id': '269', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '270', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '271', 'type': 'return_statement', 'children': ['272']} | def pprint_sequence(sequence, annotations=None, block_length=10,
blocks_per_line=6, format=PlaintextFormat):
annotations = annotations or []
partitioning = partition_range(len(sequence), annotations)
margin = int(math.floor(math.log(max(len(sequence), 1), 10))
+ 1) + len(format.margin[0])
result = (format.margin[0] + '1').rjust(margin) + format.margin[1] + ' '
for p in range(0, len(sequence), block_length):
block = [(max(start, p), min(stop, p + block_length), levels)
for start, stop, levels in partitioning
if start < p + block_length and stop > p]
result += ' '
for start, stop, levels in block:
delimiters = [(left, right) for level, (left, right)
in enumerate(format.annotations) if level in levels]
result += (''.join(left for left, right in reversed(delimiters)) +
str(sequence[start:stop]) +
''.join(right for left, right in delimiters))
if (not (p + block_length) % (block_length * blocks_per_line) and
p + block_length < len(sequence)):
result += ('\n' + (format.margin[0] +
str(p + block_length + 1)).rjust(margin) +
format.margin[1] + ' ')
return result |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '32']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'tabulate'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'v_level_indexes'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'h_level_indexes'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'v_level_visibility'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'h_level_visibility'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'v_level_sort_keys'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'h_level_sort_keys'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'v_level_titles'}, {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'h_level_titles'}; {'id': '28', 'type': 'None', 'children': []}, {'id': '29', 'type': 'default_parameter', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '31', 'type': 'string', 'children': [], 'value': '""'}; {'id': '32', 'type': 'block', 'children': ['33', '40', '54', '69', '84', '99', '109', '119', '127', '135']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'level_keys'}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'breadth_first'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'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': 'v_level_indexes'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'h_level_indexes'}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'validate_level_indexes'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '52', '53']}; {'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': 'level_keys'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'v_level_indexes'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'h_level_indexes'}; {'id': '54', 'type': 'if_statement', 'children': ['55', '58']}, {'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'is'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'v_level_visibility'}, {'id': '57', 'type': 'None', 'children': []}; {'id': '58', 'type': 'block', 'children': ['59']}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'v_level_visibility'}; {'id': '62', 'type': 'binary_operator', 'children': ['63', '65'], 'value': '*'}, {'id': '63', 'type': 'list', 'children': ['64'], 'value': '[True]'}; {'id': '64', 'type': 'True', 'children': []}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'v_level_indexes'}, {'id': '69', 'type': 'if_statement', 'children': ['70', '73']}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': 'is'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'h_level_visibility'}; {'id': '72', 'type': 'None', 'children': []}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'h_level_visibility'}, {'id': '77', 'type': 'binary_operator', 'children': ['78', '80'], 'value': '*'}; {'id': '78', 'type': 'list', 'children': ['79'], 'value': '[True]'}, {'id': '79', 'type': 'True', 'children': []}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'h_level_indexes'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '90']}; {'id': '86', 'type': 'pattern_list', 'children': ['87', '88', '89']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'v_key_tuples'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'h_key_tuples'}; {'id': '90', 'type': 'call', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'tabulate_body'}; {'id': '92', 'type': 'argument_list', 'children': ['93', '94', '95', '96', '97', '98']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'level_keys'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'v_level_indexes'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'h_level_indexes'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'v_level_sort_keys'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'h_level_sort_keys'}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '104']}, {'id': '101', 'type': 'pattern_list', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'table'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'v_key_tuples'}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'strip_missing_rows'}; {'id': '106', 'type': 'argument_list', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'v_key_tuples'}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '114']}, {'id': '111', 'type': 'pattern_list', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'table'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'h_key_tuples'}; {'id': '114', 'type': 'call', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'strip_missing_columns'}; {'id': '116', 'type': 'argument_list', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'h_key_tuples'}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'v_key_tuples'}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'strip_hidden'}; {'id': '124', 'type': 'argument_list', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'v_key_tuples'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'v_level_visibility'}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'h_key_tuples'}; {'id': '130', 'type': 'call', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'strip_hidden'}; {'id': '132', 'type': 'argument_list', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'h_key_tuples'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'h_level_visibility'}, {'id': '135', 'type': 'return_statement', 'children': ['136']}; {'id': '136', 'type': 'call', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'assemble_table'}; {'id': '138', 'type': 'argument_list', 'children': ['139', '140', '141', '142', '143', '144']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'v_key_tuples'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'h_key_tuples'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'v_level_titles'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'h_level_titles'}; {'id': '144', 'type': 'keyword_argument', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'empty'} | def tabulate(
obj,
v_level_indexes=None,
h_level_indexes=None,
v_level_visibility=None,
h_level_visibility=None,
v_level_sort_keys=None,
h_level_sort_keys=None,
v_level_titles=None,
h_level_titles=None,
empty="",
):
level_keys = breadth_first(obj)
v_level_indexes, h_level_indexes = validate_level_indexes(
len(level_keys), v_level_indexes, h_level_indexes
)
if v_level_visibility is None:
v_level_visibility = [True] * len(v_level_indexes)
if h_level_visibility is None:
h_level_visibility = [True] * len(h_level_indexes)
table, v_key_tuples, h_key_tuples = tabulate_body(
obj, level_keys, v_level_indexes, h_level_indexes, v_level_sort_keys, h_level_sort_keys
)
table, v_key_tuples = strip_missing_rows(table, v_key_tuples)
table, h_key_tuples = strip_missing_columns(table, h_key_tuples)
v_key_tuples = strip_hidden(v_key_tuples, v_level_visibility)
h_key_tuples = strip_hidden(h_key_tuples, h_level_visibility)
return assemble_table(
table, v_key_tuples, h_key_tuples, v_level_titles, h_level_titles, empty=empty
) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_ordered_entries'}, {'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': 'queryset'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '32', '155']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '11', '18']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'queryset'}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'queryset'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'queryset'}; {'id': '18', 'type': 'else_clause', 'children': ['19']}, {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'queryset'}, {'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': 'EntryCategory'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'all'}, {'id': '31', 'type': 'argument_list', 'children': []}; {'id': '32', 'type': 'if_statement', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'queryset'}; {'id': '36', 'type': 'block', 'children': ['37', '133']}, {'id': '37', 'type': 'for_statement', 'children': ['38', '39', '42']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'category'}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'queryset'}; {'id': '42', 'type': 'block', 'children': ['43', '51']}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'category'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'get_entries'}; {'id': '50', 'type': 'argument_list', 'children': []}, {'id': '51', 'type': 'if_statement', 'children': ['52', '53', '114']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'entries'}, {'id': '53', 'type': 'block', 'children': ['54', '64', '76', '88', '100', '108']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'amount_list'}, {'id': '57', 'type': 'list_comprehension', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'amount_of_views'}, {'id': '61', 'type': 'for_in_clause', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'rating_list'}, {'id': '67', 'type': 'list_comprehension', 'children': ['68', '73']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'rating'}; {'id': '72', 'type': 'argument_list', 'children': []}, {'id': '73', 'type': 'for_in_clause', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'views_per_entry'}, {'id': '79', 'type': 'binary_operator', 'children': ['80', '84'], 'value': '/'}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'fsum'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'amount_list'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'amount_list'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'rating_per_entry'}, {'id': '91', 'type': 'binary_operator', 'children': ['92', '96'], 'value': '/'}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'fsum'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'rating_list'}; {'id': '96', 'type': 'call', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'rating_list'}; {'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': 'category'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'last_rank'}, {'id': '105', 'type': 'binary_operator', 'children': ['106', '107'], 'value': '*'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'views_per_entry'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'rating_per_entry'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'category'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'save'}, {'id': '113', 'type': 'argument_list', 'children': []}; {'id': '114', 'type': 'else_clause', 'children': ['115']}, {'id': '115', 'type': 'block', 'children': ['116']}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'queryset'}, {'id': '121', 'type': 'call', 'children': ['122', '127']}; {'id': '122', 'type': 'attribute', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'queryset'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'exclude'}, {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'pk'}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'category'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'pk'}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '138']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'queryset'}; {'id': '138', 'type': 'call', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '140', 'type': 'argument_list', 'children': ['141', '144', '152']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'queryset'}; {'id': '144', 'type': 'keyword_argument', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '146', 'type': 'lambda', 'children': ['147', '149']}, {'id': '147', 'type': 'lambda_parameters', 'children': ['148']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'last_rank'}; {'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '154', 'type': 'True', 'children': []}, {'id': '155', 'type': 'return_statement', 'children': ['156']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'self'} | def get_ordered_entries(self, queryset=False):
if queryset:
self.queryset = queryset
else:
self.queryset = EntryCategory.objects.all()
if self.queryset:
for category in self.queryset:
entries = category.get_entries()
if entries:
amount_list = [e.amount_of_views for e in entries]
rating_list = [e.rating() for e in entries]
views_per_entry = fsum(amount_list) / len(amount_list)
rating_per_entry = fsum(rating_list) / len(rating_list)
category.last_rank = views_per_entry * rating_per_entry
category.save()
else:
self.queryset = self.queryset.exclude(pk=category.pk)
self.queryset = sorted(self.queryset, key=lambda c: c.last_rank,
reverse=True)
return self.queryset |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parallel_progbar'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'mapper'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'iterable'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'nprocs'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'starmap'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'flatmap'}; {'id': '14', 'type': 'False', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'shuffle'}, {'id': '17', 'type': 'False', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '20', 'type': 'True', 'children': []}, {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'verbose_flatmap'}, {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'dictionary_splat_pattern', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '26', 'type': 'block', 'children': ['27', '43']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': '_parallel_progbar_launch'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34', '35', '36', '37', '38', '39', '40', '41']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'mapper'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'iterable'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'nprocs'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'starmap'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'flatmap'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'shuffle'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'verbose_flatmap'}, {'id': '41', 'type': 'dictionary_splat', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '43', 'type': 'return_statement', 'children': ['44']}; {'id': '44', 'type': 'list_comprehension', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '46', 'type': 'for_in_clause', 'children': ['47', '50']}, {'id': '47', 'type': 'pattern_list', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '56', 'type': 'lambda', 'children': ['57', '59']}, {'id': '57', 'type': 'lambda_parameters', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '59', 'type': 'subscript', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '61', 'type': 'integer', 'children': [], 'value': '0'} | def parallel_progbar(mapper, iterable, nprocs=None, starmap=False, flatmap=False, shuffle=False,
verbose=True, verbose_flatmap=None, **kwargs):
results = _parallel_progbar_launch(mapper, iterable, nprocs, starmap, flatmap, shuffle, verbose, verbose_flatmap, **kwargs)
return [x for i, x in sorted(results, key=lambda p: p[0])] |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '30']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'iparallel_progbar'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '28']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'mapper'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'iterable'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'nprocs'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'starmap'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'flatmap'}; {'id': '14', 'type': 'False', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'shuffle'}, {'id': '17', 'type': 'False', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '20', 'type': 'True', 'children': []}, {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'verbose_flatmap'}, {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'default_parameter', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'max_cache'}; {'id': '26', 'type': 'unary_operator', 'children': ['27'], 'value': '-'}, {'id': '27', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '28', 'type': 'dictionary_splat_pattern', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '30', 'type': 'block', 'children': ['31', '48']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': '_parallel_progbar_launch'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38', '39', '40', '41', '42', '43', '44', '45', '46']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'mapper'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'iterable'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'nprocs'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'starmap'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'flatmap'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'shuffle'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'verbose_flatmap'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'max_cache'}; {'id': '46', 'type': 'dictionary_splat', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '48', 'type': 'return_statement', 'children': ['49']}, {'id': '49', 'type': 'generator_expression', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '51', 'type': 'for_in_clause', 'children': ['52', '55']}; {'id': '52', 'type': 'pattern_list', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'results'} | def iparallel_progbar(mapper, iterable, nprocs=None, starmap=False, flatmap=False, shuffle=False,
verbose=True, verbose_flatmap=None, max_cache=-1, **kwargs):
results = _parallel_progbar_launch(mapper, iterable, nprocs, starmap, flatmap, shuffle, verbose,
verbose_flatmap, max_cache, **kwargs)
return (x for i, x in results) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_creation_date_tags'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'domain'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'as_dicts'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '22', '41', '47']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'creation_date_tags'}, {'id': '13', 'type': 'list', 'children': ['14', '18'], 'value': '[\n mementoweb_api_tags(url),\n get_whois_tags(domain),\n ]'}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'mementoweb_api_tags'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'get_whois_tags'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'domain'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'creation_date_tags'}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '33']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'creation_date_tags'}; {'id': '32', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '35', 'type': 'lambda', 'children': ['36', '38']}; {'id': '36', 'type': 'lambda_parameters', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'date'}, {'id': '41', 'type': 'if_statement', 'children': ['42', '44']}; {'id': '42', 'type': 'not_operator', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'as_dicts'}; {'id': '44', 'type': 'block', 'children': ['45']}, {'id': '45', 'type': 'return_statement', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'creation_date_tags'}, {'id': '47', 'type': 'return_statement', 'children': ['48']}; {'id': '48', 'type': 'list_comprehension', 'children': ['49', '54']}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': '_as_dict'}, {'id': '53', 'type': 'argument_list', 'children': []}; {'id': '54', 'type': 'for_in_clause', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'item'} | def get_creation_date_tags(url, domain, as_dicts=False):
creation_date_tags = [
mementoweb_api_tags(url),
get_whois_tags(domain),
]
creation_date_tags = sorted(
sum(creation_date_tags, []),
key=lambda x: x.date
)
if not as_dicts:
return creation_date_tags
return [
item._as_dict()
for item in creation_date_tags
] |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'image_from_name'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'images'}; {'id': '6', 'type': 'block', 'children': ['7', '24', '50', '79']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'prefixed_images'}; {'id': '10', 'type': 'list_comprehension', 'children': ['11', '12', '15']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '12', 'type': 'for_in_clause', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'images'}, {'id': '15', 'type': 'if_clause', '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': 'i'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '34']}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'in'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '27', 'type': 'list_comprehension', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '31', 'type': 'for_in_clause', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'prefixed_images'}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'return_statement', 'children': ['36']}; {'id': '36', 'type': 'subscript', 'children': ['37', '48']}, {'id': '37', 'type': 'list_comprehension', 'children': ['38', '39', '42']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '39', 'type': 'for_in_clause', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'prefixed_images'}; {'id': '42', 'type': 'if_clause', 'children': ['43']}, {'id': '43', 'type': 'comparison_operator', 'children': ['44', '47'], 'value': '=='}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'name'}; {'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': 'decorated'}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'list_comprehension', 'children': ['57', '76']}, {'id': '57', 'type': 'tuple', 'children': ['58', '75']}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'call', 'children': ['62', '73']}; {'id': '62', 'type': 'attribute', 'children': ['63', '72']}, {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'search'}, {'id': '67', 'type': 'argument_list', 'children': ['68', '69']}; {'id': '68', 'type': 'string', 'children': [], 'value': "'\\d+'"}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'group'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '76', 'type': 'for_in_clause', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'prefixed_images'}, {'id': '79', 'type': 'return_statement', 'children': ['80']}; {'id': '80', 'type': 'subscript', 'children': ['81', '88']}, {'id': '81', 'type': 'list_comprehension', 'children': ['82', '85']}; {'id': '82', 'type': 'subscript', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '84', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '85', 'type': 'for_in_clause', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'decorated'}; {'id': '88', 'type': 'unary_operator', 'children': ['89'], 'value': '-'}, {'id': '89', 'type': 'integer', 'children': [], 'value': '1'} | def image_from_name(name, images):
prefixed_images = [i for i in images if i.name.startswith(name)]
if name in [i.name for i in prefixed_images]:
return [i for i in prefixed_images if i.name == name][-1]
decorated = sorted(
[(int(re.search('\d+', i.name).group(0)), i) for i in prefixed_images])
return [i[1] for i in decorated][-1] |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'func_on_enter'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '5', 'type': 'block', 'children': ['6', '29']}; {'id': '6', 'type': 'function_definition', 'children': ['7', '8', '10']}, {'id': '7', 'type': 'function_name', 'children': [], 'value': 'function_after_enter_pressed'}; {'id': '8', 'type': 'parameters', 'children': ['9']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '10', 'type': 'block', 'children': ['11', '17']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'ev'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'stopPropagation'}; {'id': '16', 'type': 'argument_list', 'children': []}, {'id': '17', 'type': 'if_statement', 'children': ['18', '23']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '22'], 'value': '=='}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'ev'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'keyCode'}; {'id': '22', 'type': 'integer', 'children': [], 'value': '13'}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'ev'}, {'id': '29', 'type': 'return_statement', 'children': ['30']} | def func_on_enter(func):
def function_after_enter_pressed(ev):
ev.stopPropagation()
if ev.keyCode == 13:
func(ev)
return function_after_enter_pressed |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'prev_next_group'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'project'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '6', 'type': 'block', 'children': ['7', '23', '41', '54', '72']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '12', 'type': 'generator_expression', 'children': ['13', '14', '19']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '14', 'type': 'for_in_clause', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'project'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'groups'}, {'id': '19', 'type': 'if_clause', 'children': ['20']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'submissions'}, {'id': '23', 'type': 'try_statement', 'children': ['24', '34']}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'groups'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '34', 'type': 'except_clause', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'return_statement', 'children': ['38']}; {'id': '38', 'type': 'expression_list', 'children': ['39', '40']}, {'id': '39', 'type': 'None', 'children': []}; {'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': 'prev_group'}; {'id': '44', 'type': 'conditional_expression', 'children': ['45', '50', '53'], 'value': 'if'}, {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'groups'}, {'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '-'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '49', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': '>'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '53', 'type': 'None', 'children': []}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'next_group'}, {'id': '57', 'type': 'conditional_expression', 'children': ['58', '63', '71'], 'value': 'if'}; {'id': '58', 'type': 'subscript', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '60', 'type': 'binary_operator', 'children': ['61', '62'], 'value': '+'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '62', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '63', 'type': 'comparison_operator', 'children': ['64', '67'], 'value': '<'}; {'id': '64', 'type': 'binary_operator', 'children': ['65', '66'], 'value': '+'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '66', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'groups'}, {'id': '71', 'type': 'None', 'children': []}; {'id': '72', 'type': 'return_statement', 'children': ['73']}, {'id': '73', 'type': 'expression_list', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'prev_group'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'next_group'} | def prev_next_group(project, group):
groups = sorted(x for x in project.groups if x.submissions)
try:
index = groups.index(group)
except ValueError:
return None, None
prev_group = groups[index - 1] if index > 0 else None
next_group = groups[index + 1] if index + 1 < len(groups) else None
return prev_group, next_group |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'do_minus'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'group'}, {'id': '7', 'type': 'block', 'children': ['8', '10', '18', '22', '110', '121']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'string', 'children': [], 'value': '\'\'\'This filter sorts nodes in a flat group into "required", "default",\n and "banned" subgroups based on the presence of plus and minus nodes.\n \'\'\''}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'grouper'}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'next_not'}, {'id': '21', 'type': 'None', 'children': []}; {'id': '22', 'type': 'for_statement', 'children': ['23', '24', '25']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'group'}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'if_statement', 'children': ['27', '34', '60']}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '29', 'type': 'argument_list', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'Minus'}; {'id': '34', 'type': 'block', 'children': ['35', '41', '53']}, {'id': '35', 'type': 'if_statement', 'children': ['36', '39']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'is'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'next_not'}; {'id': '38', 'type': 'None', 'children': []}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'continue_statement', 'children': []}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'next_not'}; {'id': '44', 'type': 'call', 'children': ['45', '52']}, {'id': '45', 'type': 'attribute', 'children': ['46', '51']}; {'id': '46', 'type': 'attribute', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'whoosh'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'qparser'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'syntax'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'NotGroup'}; {'id': '52', 'type': 'argument_list', 'children': []}, {'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': 'grouper'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'next_not'}; {'id': '60', 'type': 'else_clause', 'children': ['61']}, {'id': '61', 'type': 'block', 'children': ['62', '85']}; {'id': '62', 'type': 'if_statement', 'children': ['63', '74']}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '67', 'type': 'attribute', 'children': ['68', '73']}; {'id': '68', 'type': 'attribute', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'whoosh'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'qparser'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'syntax'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'GroupNode'}; {'id': '74', 'type': 'block', 'children': ['75']}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'node'}; {'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': 'do_minus'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '85', 'type': 'if_statement', 'children': ['86', '89', '101']}; {'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': 'is'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'next_not'}; {'id': '88', 'type': 'None', 'children': []}, {'id': '89', 'type': 'block', 'children': ['90', '97']}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'next_not'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'next_not'}; {'id': '100', 'type': 'None', 'children': []}, {'id': '101', 'type': 'else_clause', 'children': ['102']}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'grouper'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '110', 'type': 'if_statement', 'children': ['111', '114']}, {'id': '111', 'type': 'comparison_operator', 'children': ['112', '113'], 'value': 'is'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'next_not'}, {'id': '113', 'type': 'None', 'children': []}; {'id': '114', 'type': 'block', 'children': ['115']}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'grouper'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '120', 'type': 'argument_list', 'children': []}, {'id': '121', 'type': 'return_statement', 'children': ['122']} | def do_minus(self, parser, group):
'''This filter sorts nodes in a flat group into "required", "default",
and "banned" subgroups based on the presence of plus and minus nodes.
'''
grouper = group.__class__()
next_not = None
for node in group:
if isinstance(node, self.Minus):
if next_not is not None:
continue
next_not = whoosh.qparser.syntax.NotGroup()
grouper.append(next_not)
else:
if isinstance(node, whoosh.qparser.syntax.GroupNode):
node = self.do_minus(parser, node)
if next_not is not None:
next_not.append(node)
next_not = None
else:
grouper.append(node)
if next_not is not None:
grouper.pop()
return grouper |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'topological_sort'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dependency_pairs'}, {'id': '5', 'type': 'block', 'children': ['6', '8', '15', '22', '26', '68', '80', '109', '125']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'string', 'children': [], 'value': '"Sort values subject to dependency constraints"'}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'num_heads'}, {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'tails'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'heads'}, {'id': '25', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '26', 'type': 'for_statement', 'children': ['27', '30', '31']}, {'id': '27', 'type': 'pattern_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'h'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'dependency_pairs'}, {'id': '31', 'type': 'block', 'children': ['32', '38']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'augmented_assignment', 'children': ['34', '37'], 'value': '+='}; {'id': '34', 'type': 'subscript', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'num_heads'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '37', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '38', 'type': 'if_statement', 'children': ['39', '42', '52']}, {'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'in'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'h'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'tails'}; {'id': '42', 'type': 'block', 'children': ['43']}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '50']}, {'id': '45', 'type': 'attribute', 'children': ['46', '49']}; {'id': '46', 'type': 'subscript', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'tails'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'h'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '52', 'type': 'else_clause', 'children': ['53']}, {'id': '53', 'type': 'block', 'children': ['54', '61']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '59']}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'tails'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'h'}, {'id': '59', 'type': 'list', 'children': ['60'], 'value': '[t]'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'call', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'heads'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'ordered'}, {'id': '71', 'type': 'list_comprehension', 'children': ['72', '73', '76']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'h'}, {'id': '73', 'type': 'for_in_clause', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'h'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'heads'}; {'id': '76', 'type': 'if_clause', 'children': ['77']}, {'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': 'not'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'h'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'num_heads'}; {'id': '80', 'type': 'for_statement', 'children': ['81', '82', '83']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'ordered'}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'for_statement', 'children': ['85', '86', '89']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '86', 'type': 'subscript', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'tails'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'h'}, {'id': '89', 'type': 'block', 'children': ['90', '96']}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'augmented_assignment', 'children': ['92', '95'], 'value': '-='}; {'id': '92', 'type': 'subscript', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'num_heads'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '95', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '96', 'type': 'if_statement', 'children': ['97', '101']}, {'id': '97', 'type': 'not_operator', 'children': ['98']}; {'id': '98', 'type': 'subscript', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'num_heads'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'ordered'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'cyclic'}; {'id': '112', 'type': 'list_comprehension', 'children': ['113', '114', '123']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '114', 'type': 'for_in_clause', 'children': ['115', '118']}, {'id': '115', 'type': 'pattern_list', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'heads'}; {'id': '118', 'type': 'call', 'children': ['119', '122']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'num_heads'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '122', 'type': 'argument_list', 'children': []}, {'id': '123', 'type': 'if_clause', 'children': ['124']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'heads'}, {'id': '125', 'type': 'return_statement', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'Results'}; {'id': '128', 'type': 'argument_list', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'ordered'} | def topological_sort(dependency_pairs):
"Sort values subject to dependency constraints"
num_heads = defaultdict(int)
tails = defaultdict(list)
heads = []
for h, t in dependency_pairs:
num_heads[t] += 1
if h in tails:
tails[h].append(t)
else:
tails[h] = [t]
heads.append(h)
ordered = [h for h in heads if h not in num_heads]
for h in ordered:
for t in tails[h]:
num_heads[t] -= 1
if not num_heads[t]:
ordered.append(t)
cyclic = [n for n, heads in num_heads.items() if heads]
return Results(ordered, cyclic) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'multisorted'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '5', 'type': 'list_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '7', 'type': 'block', 'children': ['8', '23', '47']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '15']}, {'id': '9', 'type': 'comparison_operator', 'children': ['10', '14'], 'value': '=='}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '14', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '19', 'type': 'list', 'children': ['20'], 'value': '[asc()]'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'asc'}; {'id': '22', 'type': 'argument_list', 'children': []}, {'id': '23', 'type': 'for_statement', 'children': ['24', '25', '29']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'reversed'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '35', 'type': 'argument_list', 'children': ['36', '37', '42']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '47', 'type': 'return_statement', 'children': ['48']} | def multisorted(items, *keys):
if len(keys) == 0:
keys = [asc()]
for key in reversed(keys):
items = sorted(items, key=key.func, reverse=key.reverse)
return items |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'tuplesorted'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '5', 'type': 'list_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '7', 'type': 'block', 'children': ['8', '47']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'tuple_keys'}, {'id': '11', 'type': 'list_comprehension', 'children': ['12', '39']}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'Key'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '34']}, {'id': '15', 'type': 'keyword_argument', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '17', 'type': 'lambda', 'children': ['18', '26']}; {'id': '18', 'type': 'lambda_parameters', 'children': ['19', '20', '23']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'subscript', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '39', 'type': 'for_in_clause', 'children': ['40', '43']}; {'id': '40', 'type': 'pattern_list', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '47', 'type': 'return_statement', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'multisorted'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '52', 'type': 'list_splat', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'tuple_keys'} | def tuplesorted(items, *keys):
tuple_keys = [
Key(func=lambda t, i=index, k=key: k.func(t[i]), reverse=key.reverse)
for index, key in enumerate(keys)
]
return multisorted(items, *tuple_keys) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_formats'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '8', 'type': 'tuple', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'formats'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '22', '42', '56']}, {'id': '13', 'type': 'if_statement', 'children': ['14', '17']}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': '=='}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'formats'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'formats'}, {'id': '21', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '22', 'type': 'for_statement', 'children': ['23', '24', '27']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'list_formats'}, {'id': '33', 'type': 'argument_list', 'children': ['34', '35', '41']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '35', 'type': 'binary_operator', 'children': ['36', '37'], 'value': '+'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '37', 'type': 'tuple', 'children': ['38']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'formats'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'boolean_operator', 'children': ['44', '45'], 'value': 'and'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'formats'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'string', 'children': [], 'value': '"."'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '56', 'type': 'return_statement', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '59', 'type': 'argument_list', 'children': ['60']} | def list_formats(self, node, path=(), formats=None):
if formats == None:
formats = []
for child in node.children:
self.list_formats(child, path + (child.name,), formats)
path and formats.append(".".join(path))
return sorted(formats) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'ls'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '6', 'type': 'string', 'children': [], 'value': '"."'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'abspaths'}, {'id': '9', 'type': 'False', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'recursive'}; {'id': '12', 'type': 'False', 'children': []}, {'id': '13', 'type': 'block', 'children': ['14', '57']}; {'id': '14', 'type': 'function_definition', 'children': ['15', '16', '18']}, {'id': '15', 'type': 'function_name', 'children': [], 'value': '_expand_subdirs'}; {'id': '16', 'type': 'parameters', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '18', 'type': 'block', 'children': ['19']}, {'id': '19', 'type': 'if_statement', 'children': ['20', '28', '52']}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '25', 'type': 'argument_list', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'return_statement', 'children': ['30']}; {'id': '30', 'type': 'binary_operator', 'children': ['31', '33'], 'value': '+'}, {'id': '31', 'type': 'list', 'children': ['32'], 'value': '[file]'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'file'}, {'id': '33', 'type': 'list_comprehension', 'children': ['34', '39']}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '39', 'type': 'for_in_clause', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'ls'}, {'id': '43', 'type': 'argument_list', 'children': ['44', '49']}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'file'}, {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'recursive'}, {'id': '51', 'type': 'True', 'children': []}; {'id': '52', 'type': 'else_clause', 'children': ['53']}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'return_statement', 'children': ['55']}, {'id': '55', 'type': 'list', 'children': ['56'], 'value': '[file]'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'file'}, {'id': '57', 'type': 'if_statement', 'children': ['58', '62', '76', '109', '139']}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'return_statement', 'children': ['64']}; {'id': '64', 'type': 'conditional_expression', 'children': ['65', '70', '71'], 'value': 'if'}, {'id': '65', 'type': 'list', 'children': ['66'], 'value': '[abspath(root)]'}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'abspath'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'abspaths'}, {'id': '71', 'type': 'list', 'children': ['72'], 'value': '[basename(root)]'}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '76', 'type': 'elif_clause', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'abspaths'}; {'id': '78', 'type': 'block', 'children': ['79', '92', '99']}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'relpaths'}; {'id': '82', 'type': 'call', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'ls'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '86', '89']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'recursive'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'recursive'}, {'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'abspaths'}, {'id': '91', 'type': 'False', 'children': []}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'abspath'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '99', 'type': 'return_statement', 'children': ['100']}; {'id': '100', 'type': 'list_comprehension', 'children': ['101', '106']}, {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '103', 'type': 'argument_list', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'relpath'}; {'id': '106', 'type': 'for_in_clause', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'relpath'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'relpaths'}, {'id': '109', 'type': 'elif_clause', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'recursive'}, {'id': '111', 'type': 'block', 'children': ['112', '125']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'paths'}, {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'ls'}, {'id': '117', 'type': 'argument_list', 'children': ['118', '119', '122']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'abspaths'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'abspaths'}; {'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'recursive'}; {'id': '124', 'type': 'False', 'children': []}, {'id': '125', 'type': 'return_statement', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'labtypes'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'flatten'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'list_comprehension', 'children': ['132', '136']}; {'id': '132', 'type': 'call', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': '_expand_subdirs'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '136', 'type': 'for_in_clause', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'paths'}, {'id': '139', 'type': 'else_clause', 'children': ['140']}; {'id': '140', 'type': 'block', 'children': ['141']}, {'id': '141', 'type': 'return_statement', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'call', 'children': ['149', '152']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'listdir'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'root'} | def ls(root=".", abspaths=False, recursive=False):
def _expand_subdirs(file):
if isdir(path(root, file)):
return [file] + [path(file, x) for x in
ls(path(root, file), recursive=True)]
else:
return [file]
if isfile(root):
return [abspath(root)] if abspaths else [basename(root)]
elif abspaths:
relpaths = ls(root, recursive=recursive, abspaths=False)
base = abspath(root)
return [path(base, relpath) for relpath in relpaths]
elif recursive:
paths = ls(root, abspaths=abspaths, recursive=False)
return labtypes.flatten([_expand_subdirs(file) for file in paths])
else:
return list(sorted(os.listdir(root))) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '7', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'dictionary_splat_pattern', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'try_statement', 'children': ['21', '55']}, {'id': '21', 'type': 'block', 'children': ['22', '44']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'cursor'}, {'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': '_cursor'}, {'id': '29', 'type': 'argument_list', 'children': ['30', '33', '36', '39', '42']}; {'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '42', 'type': 'dictionary_splat', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '44', 'type': 'return_statement', 'children': ['45']}, {'id': '45', 'type': 'expression_list', 'children': ['46', '50']}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'cursor'}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'cursor'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '54', 'type': 'argument_list', 'children': []}, {'id': '55', 'type': 'except_clause', 'children': ['56', '64']}; {'id': '56', 'type': 'as_pattern', 'children': ['57', '62']}, {'id': '57', 'type': 'attribute', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'pymongo'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'OperationFailure'}; {'id': '62', 'type': 'as_pattern_target', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'exc'}; {'id': '64', 'type': 'block', 'children': ['65', '84', '91', '102', '110', '132']}, {'id': '65', 'type': 'try_statement', 'children': ['66', '77']}; {'id': '66', 'type': 'block', 'children': ['67']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'subscript', 'children': ['69', '76']}, {'id': '69', 'type': 'subscript', 'children': ['70', '75']}; {'id': '70', 'type': 'subscript', 'children': ['71', '74']}, {'id': '71', 'type': 'subscript', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '73', 'type': 'string', 'children': [], 'value': "'$or'"}; {'id': '74', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '75', 'type': 'string', 'children': [], 'value': "'$text'"}; {'id': '76', 'type': 'string', 'children': [], 'value': "'$search'"}, {'id': '77', 'type': 'except_clause', 'children': ['78', '81']}; {'id': '78', 'type': 'tuple', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'IndexError'}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'raise_statement', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'exc'}; {'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': 'LOG'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'warn'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'string', 'children': [], 'value': '"Falling back to hard-coded mongo v2.4 search behavior"'}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '94', 'type': 'call', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'search_alternative'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '100', 'type': 'dictionary_splat', 'children': ['101']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'LOG'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '107', 'type': 'argument_list', 'children': ['108', '109']}; {'id': '108', 'type': 'string', 'children': [], 'value': '"Modified kwargs: %s"'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'cursor'}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': '_cursor'}, {'id': '117', 'type': 'argument_list', 'children': ['118', '121', '124', '127', '130']}; {'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '121', 'type': 'keyword_argument', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '130', 'type': 'dictionary_splat', 'children': ['131']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '132', 'type': 'return_statement', 'children': ['133']}, {'id': '133', 'type': 'expression_list', 'children': ['134', '138']}; {'id': '134', 'type': 'call', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'cursor'}; {'id': '138', 'type': 'call', 'children': ['139', '142']}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'cursor'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'count'} | def list(self, offset=0, limit=0, fields=None, sort=None, **kwargs):
try:
cursor = self._cursor(offset=offset, limit=limit, fields=fields,
sort=sort, **kwargs)
return list(cursor), cursor.count()
except pymongo.errors.OperationFailure as exc:
try:
kwargs['$or'][0]['$text']['$search']
except (KeyError, IndexError):
raise exc
LOG.warn("Falling back to hard-coded mongo v2.4 search behavior")
kwargs = self.search_alternative(limit, **kwargs)
LOG.debug("Modified kwargs: %s", kwargs)
cursor = self._cursor(offset=offset, limit=limit, fields=fields,
sort=sort, **kwargs)
return list(cursor), cursor.count() |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_cursor'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '7', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'dictionary_splat_pattern', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '19', 'type': 'block', 'children': ['20', '27', '43', '55', '114', '130']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'projection'}, {'id': '23', 'type': 'dictionary', 'children': ['24']}; {'id': '24', 'type': 'pair', 'children': ['25', '26']}, {'id': '25', 'type': 'string', 'children': [], 'value': "'_id'"}; {'id': '26', 'type': 'False', 'children': []}, {'id': '27', 'type': 'if_statement', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'projection'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'dictionary_comprehension', 'children': ['37', '40']}, {'id': '37', 'type': 'pair', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '39', 'type': 'True', 'children': []}; {'id': '40', 'type': 'for_in_clause', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'results'}; {'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': '_collection'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'projection'}, {'id': '55', 'type': 'if_statement', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '57', 'type': 'block', 'children': ['58', '65', '107']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'sort_pairs'}, {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '63', 'type': 'slice', 'children': ['64']}; {'id': '64', 'type': 'colon', 'children': []}, {'id': '65', 'type': 'for_statement', 'children': ['66', '69', '73']}; {'id': '66', 'type': 'pattern_list', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'if_statement', 'children': ['75', '80', '95']}, {'id': '75', 'type': 'comparison_operator', 'children': ['76', '79'], 'value': '=='}; {'id': '76', 'type': 'subscript', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '78', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '79', 'type': 'string', 'children': [], 'value': '"-"'}; {'id': '80', 'type': 'block', 'children': ['81']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '86']}, {'id': '83', 'type': 'subscript', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'sort_pairs'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '86', 'type': 'tuple', 'children': ['87', '92']}, {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '89', 'type': 'slice', 'children': ['90', '91']}; {'id': '90', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '91', 'type': 'colon', 'children': []}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'pymongo'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'DESCENDING'}, {'id': '95', 'type': 'else_clause', 'children': ['96']}; {'id': '96', 'type': 'block', 'children': ['97']}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '102']}, {'id': '99', 'type': 'subscript', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'sort_pairs'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '102', 'type': 'tuple', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'pymongo'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'ASCENDING'}, {'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': 'results'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'sort_pairs'}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'call', 'children': ['116', '126']}; {'id': '116', 'type': 'attribute', 'children': ['117', '125']}, {'id': '117', 'type': 'call', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'skip'}, {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'boolean_operator', 'children': ['123', '124'], 'value': 'or'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '124', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'boolean_operator', 'children': ['128', '129'], 'value': 'or'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '129', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '130', 'type': 'return_statement', 'children': ['131']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'results'} | def _cursor(self, offset=0, limit=0, fields=None, sort=None, **kwargs):
projection = {'_id': False}
if fields:
projection.update({field: True for field in fields})
results = self._collection.find(kwargs, projection)
if sort:
sort_pairs = sort[:]
for index, field in enumerate(sort):
if field[0] == "-":
sort_pairs[index] = (field[1:], pymongo.DESCENDING)
else:
sort_pairs[index] = (field, pymongo.ASCENDING)
results.sort(sort_pairs)
results.skip(offset or 0).limit(limit or 0)
return results |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'insert'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'low_value'}, {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'return_statement', 'children': ['9']}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'c_void_p'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'lib'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'zlistx_insert'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '20', '21']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': '_as_parameter_'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'low_value'} | def insert(self, item, low_value):
return c_void_p(lib.zlistx_insert(self._as_parameter_, item, low_value)) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'reorder'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'handle'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'low_value'}, {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'return_statement', 'children': ['9']}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'zlistx_reorder'}, {'id': '13', 'type': 'argument_list', 'children': ['14', '17', '18']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '_as_parameter_'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'handle'} | def reorder(self, handle, low_value):
return lib.zlistx_reorder(self._as_parameter_, handle, low_value) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'process_params'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'standard_params'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'STANDARD_QUERY_PARAMS'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'filter_fields'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'defaults'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '23', '47', '74', '80', '148', '195', '241']}, {'id': '15', 'type': 'if_statement', 'children': ['16', '18']}; {'id': '16', 'type': 'not_operator', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'filter_fields'}; {'id': '18', 'type': 'block', 'children': ['19']}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'filter_fields'}; {'id': '22', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'unfilterable'}; {'id': '26', 'type': 'parenthesized_expression', 'children': ['27'], 'value': '()'}, {'id': '27', 'type': 'binary_operator', 'children': ['28', '43'], 'value': '-'}; {'id': '28', 'type': 'binary_operator', 'children': ['29', '39'], 'value': '-'}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '38']}, {'id': '33', 'type': 'attribute', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '38', 'type': 'argument_list', 'children': []}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'filter_fields'}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'standard_params'}, {'id': '47', 'type': 'if_statement', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'unfilterable'}, {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'bottle'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'abort'}, {'id': '55', 'type': 'argument_list', 'children': ['56', '57']}; {'id': '56', 'type': 'integer', 'children': [], 'value': '400'}, {'id': '57', 'type': 'binary_operator', 'children': ['58', '61'], 'value': '%'}; {'id': '58', 'type': 'concatenated_string', 'children': ['59', '60']}, {'id': '59', 'type': 'string', 'children': [], 'value': '"The following query params were invalid: %s. "'}; {'id': '60', 'type': 'string', 'children': [], 'value': '"Try one (or more) of %s."'}, {'id': '61', 'type': 'tuple', 'children': ['62', '68']}; {'id': '62', 'type': 'call', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'string', 'children': [], 'value': '", "'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'unfilterable'}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'string', 'children': [], 'value': '", "'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'filter_fields'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'query_fields'}, {'id': '77', 'type': 'boolean_operator', 'children': ['78', '79'], 'value': 'or'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'defaults'}, {'id': '79', 'type': 'dictionary', 'children': []}; {'id': '80', 'type': 'for_statement', 'children': ['81', '82', '85']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'if_statement', 'children': ['87', '90']}, {'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': 'in'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'filter_fields'}; {'id': '90', 'type': 'block', 'children': ['91', '102', '124']}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'matches'}; {'id': '94', 'type': 'call', 'children': ['95', '100']}, {'id': '95', 'type': 'attribute', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'getall'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'matches'}, {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'call', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'itertools'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'chain'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'list_splat', 'children': ['114']}; {'id': '114', 'type': 'generator_expression', 'children': ['115', '121']}, {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'string', 'children': [], 'value': "','"}, {'id': '121', 'type': 'for_in_clause', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'matches'}; {'id': '124', 'type': 'if_statement', 'children': ['125', '131', '138']}, {'id': '125', 'type': 'comparison_operator', 'children': ['126', '130'], 'value': '>'}; {'id': '126', 'type': 'call', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'matches'}; {'id': '130', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '137']}; {'id': '134', 'type': 'subscript', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'query_fields'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'matches'}; {'id': '138', 'type': 'else_clause', 'children': ['139']}, {'id': '139', 'type': 'block', 'children': ['140']}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '145']}; {'id': '142', 'type': 'subscript', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'query_fields'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'matches'}, {'id': '147', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '148', 'type': 'if_statement', 'children': ['149', '154']}, {'id': '149', 'type': 'comparison_operator', 'children': ['150', '151'], 'value': 'in'}; {'id': '150', 'type': 'string', 'children': [], 'value': "'sort'"}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '154', 'type': 'block', 'children': ['155', '166', '189']}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '158', 'type': 'call', 'children': ['159', '164']}, {'id': '159', 'type': 'attribute', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'getall'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'string', 'children': [], 'value': "'sort'"}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'assignment', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'call', 'children': ['173', '176']}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'itertools'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'chain'}; {'id': '176', 'type': 'argument_list', 'children': ['177']}, {'id': '177', 'type': 'list_splat', 'children': ['178']}; {'id': '178', 'type': 'generator_expression', 'children': ['179', '186']}, {'id': '179', 'type': 'call', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'comma_separated_strings'}, {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'call', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '186', 'type': 'for_in_clause', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '194']}, {'id': '191', 'type': 'subscript', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'query_fields'}, {'id': '193', 'type': 'string', 'children': [], 'value': "'sort'"}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '195', 'type': 'if_statement', 'children': ['196', '201']}; {'id': '196', 'type': 'comparison_operator', 'children': ['197', '198'], 'value': 'in'}, {'id': '197', 'type': 'string', 'children': [], 'value': "'q'"}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '201', 'type': 'block', 'children': ['202', '213', '235']}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'assignment', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'search'}, {'id': '205', 'type': 'call', 'children': ['206', '211']}; {'id': '206', 'type': 'attribute', 'children': ['207', '210']}, {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'getall'}, {'id': '211', 'type': 'argument_list', 'children': ['212']}; {'id': '212', 'type': 'string', 'children': [], 'value': "'q'"}, {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'assignment', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'search'}; {'id': '216', 'type': 'call', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '218', 'type': 'argument_list', 'children': ['219']}, {'id': '219', 'type': 'call', 'children': ['220', '223']}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'itertools'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'chain'}, {'id': '223', 'type': 'argument_list', 'children': ['224']}; {'id': '224', 'type': 'list_splat', 'children': ['225']}, {'id': '225', 'type': 'generator_expression', 'children': ['226', '230', '233']}; {'id': '226', 'type': 'call', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'comma_separated_strings'}; {'id': '228', 'type': 'argument_list', 'children': ['229']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '230', 'type': 'for_in_clause', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'search'}, {'id': '233', 'type': 'if_clause', 'children': ['234']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'assignment', 'children': ['237', '240']}, {'id': '237', 'type': 'subscript', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'query_fields'}, {'id': '239', 'type': 'string', 'children': [], 'value': "'q'"}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'search'}, {'id': '241', 'type': 'return_statement', 'children': ['242']} | def process_params(request, standard_params=STANDARD_QUERY_PARAMS,
filter_fields=None, defaults=None):
if not filter_fields:
filter_fields = []
unfilterable = (set(request.query.keys()) - set(filter_fields) -
set(standard_params))
if unfilterable:
bottle.abort(400,
"The following query params were invalid: %s. "
"Try one (or more) of %s." %
(", ".join(unfilterable),
", ".join(filter_fields)))
query_fields = defaults or {}
for key in request.query:
if key in filter_fields:
matches = request.query.getall(key)
matches = list(itertools.chain(*(k.split(',') for k in matches)))
if len(matches) > 1:
query_fields[key] = matches
else:
query_fields[key] = matches[0]
if 'sort' in request.query:
sort = request.query.getall('sort')
sort = list(itertools.chain(*(
comma_separated_strings(str(k)) for k in sort)))
query_fields['sort'] = sort
if 'q' in request.query:
search = request.query.getall('q')
search = list(itertools.chain(*(
comma_separated_strings(k) for k in search
if k)))
query_fields['q'] = search
return query_fields |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_weave_dohist'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'binsize'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'hist'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'rev'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'dorev'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '14', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '15', 'type': 'block', 'children': ['16', '29', '59']}; {'id': '16', 'type': 'if_statement', 'children': ['17', '18', '23']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'dorev'}; {'id': '18', 'type': 'block', 'children': ['19']}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'dorev'}; {'id': '22', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '23', 'type': 'else_clause', 'children': ['24']}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'dorev'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'code'}; {'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': 'scipy'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'weave'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'inline'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40', '47', '56']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '40', 'type': 'list', 'children': ['41', '42', '43', '44', '45', '46'], 'value': "['data','s','binsize','hist','rev','dorev']"}, {'id': '41', 'type': 'string', 'children': [], 'value': "'data'"}; {'id': '42', 'type': 'string', 'children': [], 'value': "'s'"}, {'id': '43', 'type': 'string', 'children': [], 'value': "'binsize'"}; {'id': '44', 'type': 'string', 'children': [], 'value': "'hist'"}, {'id': '45', 'type': 'string', 'children': [], 'value': "'rev'"}; {'id': '46', 'type': 'string', 'children': [], 'value': "'dorev'"}, {'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'type_converters'}, {'id': '49', 'type': 'attribute', 'children': ['50', '55']}; {'id': '50', 'type': 'attribute', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'scipy'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'weave'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'converters'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'blitz'}; {'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '59', 'type': 'return_statement', 'children': []} | def _weave_dohist(data, s, binsize, hist, rev, dorev=False, verbose=0):
if dorev:
dorev=1
else:
dorev=0
code =
scipy.weave.inline(code, ['data','s','binsize','hist','rev','dorev'],
type_converters = scipy.weave.converters.blitz, verbose=verbose)
return |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'loose_search'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'asset_manager_id'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '8', 'type': 'string', 'children': [], 'value': "''"}, {'id': '9', 'type': 'dictionary_splat_pattern', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '11', 'type': 'block', 'children': ['12', '22', '38', '45', '90', '104']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'call', 'children': ['14', '19']}; {'id': '14', 'type': 'attribute', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '19', 'type': 'argument_list', 'children': ['20', '21']}; {'id': '20', 'type': 'string', 'children': [], 'value': "'Asset Search - Asset Manager: %s'"}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'asset_manager_id'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'string', 'children': [], 'value': "'{endpoint}/assets/search/{asset_manager_id}'"}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '29', 'type': 'argument_list', 'children': ['30', '33']}; {'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'asset_manager_id'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'asset_manager_id'}, {'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'endpoint'}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'endpoint'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '41', 'type': 'dictionary', 'children': ['42']}; {'id': '42', 'type': 'pair', 'children': ['43', '44']}, {'id': '43', 'type': 'string', 'children': [], 'value': "'query'"}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '45', 'type': 'for_statement', 'children': ['46', '49', '54']}; {'id': '46', 'type': 'pattern_list', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'k'}; {'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': 'kwargs'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '53', 'type': 'argument_list', 'children': []}; {'id': '54', 'type': 'block', 'children': ['55', '84']}, {'id': '55', 'type': 'if_statement', 'children': ['56', '68']}; {'id': '56', 'type': 'boolean_operator', 'children': ['57', '63'], 'value': 'and'}, {'id': '57', 'type': 'not_operator', 'children': ['58']}; {'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': 'v'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'Iterable'}; {'id': '68', 'type': 'block', 'children': ['69']}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'string', 'children': [], 'value': "','"}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '76', 'type': 'generator_expression', 'children': ['77', '81']}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '81', 'type': 'for_in_clause', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '89']}; {'id': '86', 'type': 'subscript', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '93', 'type': 'call', 'children': ['94', '99']}; {'id': '94', 'type': 'attribute', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '99', 'type': 'argument_list', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '104', 'type': 'if_statement', 'children': ['105', '108', '149']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'ok'}; {'id': '108', 'type': 'block', 'children': ['109', '117', '134', '147']}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '112', 'type': 'call', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'json'}; {'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': 'assets'}; {'id': '120', 'type': 'list_comprehension', 'children': ['121', '125']}, {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'json_to_asset'}, {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'json_asset'}, {'id': '125', 'type': 'for_in_clause', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'json_asset'}, {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '131', 'type': 'argument_list', 'children': ['132', '133']}; {'id': '132', 'type': 'string', 'children': [], 'value': "'hits'"}, {'id': '133', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'call', 'children': ['136', '141']}; {'id': '136', 'type': 'attribute', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '141', 'type': 'argument_list', 'children': ['142', '143']}; {'id': '142', 'type': 'string', 'children': [], 'value': "'Returned %s Assets.'"}, {'id': '143', 'type': 'call', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'assets'}, {'id': '147', 'type': 'return_statement', 'children': ['148']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'assets'}, {'id': '149', 'type': 'else_clause', 'children': ['150']}; {'id': '150', 'type': 'block', 'children': ['151', '162']}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '158']}, {'id': '153', 'type': 'attribute', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}, {'id': '163', 'type': 'call', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'raise_for_status'}, {'id': '167', 'type': 'argument_list', 'children': []} | def loose_search(self, asset_manager_id, query='', **kwargs):
self.logger.info('Asset Search - Asset Manager: %s', asset_manager_id)
url = '{endpoint}/assets/search/{asset_manager_id}'.format(
asset_manager_id=asset_manager_id,
endpoint=self.endpoint,
)
params = {'query': query}
for k, v in kwargs.items():
if not isinstance(v, str) and isinstance(v, Iterable):
v = ','.join(str(i) for i in v)
params[k] = v
response = self.session.get(url, params=params)
if response.ok:
data = response.json()
assets = [json_to_asset(json_asset) for json_asset in data.get('hits', [])]
self.logger.info('Returned %s Assets.', len(assets))
return assets
else:
self.logger.error(response.text)
response.raise_for_status() |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'natural_sort'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '5', 'type': 'block', 'children': ['6', '13', '30']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '10']}, {'id': '7', 'type': 'comparison_operator', 'children': ['8', '9'], 'value': 'is'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11']}, {'id': '11', 'type': 'return_statement', 'children': ['12']}; {'id': '12', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '13', 'type': 'function_definition', 'children': ['14', '15', '17']}; {'id': '14', 'type': 'function_name', 'children': [], 'value': 'try_int'}, {'id': '15', 'type': 'parameters', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'try_statement', 'children': ['19', '25']}, {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'return_statement', 'children': ['21']}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '25', 'type': 'except_clause', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'return_statement', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '30', 'type': 'return_statement', 'children': ['31']}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'try_int'}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'findall'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44']}, {'id': '43', 'type': 'string', 'children': [], 'value': "r'(\\d+|\\D+)'"} | def natural_sort(item):
if item is None:
return 0
def try_int(s):
try:
return int(s)
except ValueError:
return s
return tuple(map(try_int, re.findall(r'(\d+|\D+)', item))) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_html_attrs'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '6', 'type': 'None', 'children': []}, {'id': '7', 'type': 'block', 'children': ['8', '14', '18', '22', '36', '73', '83', '151', '157', '163', '170']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '11', 'type': 'boolean_operator', 'children': ['12', '13'], 'value': 'or'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '13', 'type': 'dictionary', 'children': []}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '17', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'props'}, {'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': 'classes'}, {'id': '25', 'type': 'call', 'children': ['26', '35']}; {'id': '26', 'type': 'attribute', 'children': ['27', '34']}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': "'classes'"}, {'id': '33', 'type': 'string', 'children': [], 'value': "''"}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'if_statement', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'classes'}; {'id': '38', 'type': 'block', 'children': ['39', '54', '64']}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'classes'}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '51', 'type': 'argument_list', 'children': ['52', '53']}; {'id': '52', 'type': 'string', 'children': [], 'value': "r'\\s+'"}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'classes'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'classes'}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'to_unicode'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'quoteattr'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'classes'}; {'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': 'attrs'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'binary_operator', 'children': ['71', '72'], 'value': '%'}, {'id': '71', 'type': 'string', 'children': [], 'value': "'class=%s'"}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'classes'}, {'id': '73', 'type': 'try_statement', 'children': ['74', '79']}; {'id': '74', 'type': 'block', 'children': ['75']}, {'id': '75', 'type': 'delete_statement', 'children': ['76']}; {'id': '76', 'type': 'subscript', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '78', 'type': 'string', 'children': [], 'value': "'classes'"}, {'id': '79', 'type': 'except_clause', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'KeyError'}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'pass_statement', 'children': []}, {'id': '83', 'type': 'for_statement', 'children': ['84', '87', '91']}; {'id': '84', 'type': 'pattern_list', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'iteritems'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '91', 'type': 'block', 'children': ['92', '102', '109']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '99', 'type': 'argument_list', 'children': ['100', '101']}; {'id': '100', 'type': 'string', 'children': [], 'value': "'_'"}, {'id': '101', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'to_unicode'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '109', 'type': 'if_statement', 'children': ['110', '115', '128']}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '112', 'type': 'argument_list', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'bool'}, {'id': '115', 'type': 'block', 'children': ['116']}; {'id': '116', 'type': 'if_statement', 'children': ['117', '120']}, {'id': '117', 'type': 'comparison_operator', 'children': ['118', '119'], 'value': 'is'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '119', 'type': 'True', 'children': []}; {'id': '120', 'type': 'block', 'children': ['121']}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'props'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '128', 'type': 'else_clause', 'children': ['129']}, {'id': '129', 'type': 'block', 'children': ['130', '140']}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'assignment', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'quoteattr'}, {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'call', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'Markup'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'binary_operator', 'children': ['147', '148'], 'value': '%'}, {'id': '147', 'type': 'string', 'children': [], 'value': "u'%s=%s'"}; {'id': '148', 'type': 'tuple', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '156', 'type': 'argument_list', 'children': []}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'call', 'children': ['159', '162']}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'props'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '162', 'type': 'argument_list', 'children': []}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'call', 'children': ['165', '168']}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'props'}; {'id': '170', 'type': 'return_statement', 'children': ['171']}, {'id': '171', 'type': 'call', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'string', 'children': [], 'value': "u' '"}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '175', 'type': 'argument_list', 'children': ['176']} | def get_html_attrs(kwargs=None):
kwargs = kwargs or {}
attrs = []
props = []
classes = kwargs.get('classes', '').strip()
if classes:
classes = ' '.join(re.split(r'\s+', classes))
classes = to_unicode(quoteattr(classes))
attrs.append('class=%s' % classes)
try:
del kwargs['classes']
except KeyError:
pass
for key, value in iteritems(kwargs):
key = key.replace('_', '-')
key = to_unicode(key)
if isinstance(value, bool):
if value is True:
props.append(key)
else:
value = quoteattr(Markup(value))
attrs.append(u'%s=%s' % (key, value))
attrs.sort()
props.sort()
attrs.extend(props)
return u' '.join(attrs) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_dependencies'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'objects'}, {'id': '5', 'type': 'block', 'children': ['6', '13', '17', '23', '29', '36', '62', '172', '178', '182', '308', '312', '325']}; {'id': '6', 'type': 'import_from_statement', 'children': ['7', '11']}, {'id': '7', 'type': 'dotted_name', 'children': ['8', '9', '10']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'django'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'models'}, {'id': '11', 'type': 'dotted_name', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'get_model'}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'model_dependencies'}; {'id': '16', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'models'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '22', 'type': 'argument_list', 'children': []}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'model_list'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '28', 'type': 'argument_list', 'children': []}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'objs_by_model'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '36', 'type': 'for_statement', 'children': ['37', '38', '39']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'objects'}, {'id': '39', 'type': 'block', 'children': ['40', '46', '55']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'o'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'call', 'children': ['48', '53']}; {'id': '48', 'type': 'attribute', 'children': ['49', '52']}, {'id': '49', 'type': 'subscript', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'objs_by_model'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'o'}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'model_list'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '62', 'type': 'for_statement', 'children': ['63', '64', '65']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'model_list'}, {'id': '65', 'type': 'block', 'children': ['66', '73', '117', '163']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'models'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '73', 'type': 'if_statement', 'children': ['74', '79', '111']}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '78', 'type': 'string', 'children': [], 'value': "'natural_key'"}, {'id': '79', 'type': 'block', 'children': ['80', '91']}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'deps'}, {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '85', 'type': 'argument_list', 'children': ['86', '89', '90']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'natural_key'}, {'id': '89', 'type': 'string', 'children': [], 'value': "'dependencies'"}; {'id': '90', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '91', 'type': 'if_statement', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'deps'}, {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'deps'}, {'id': '97', 'type': 'list_comprehension', 'children': ['98', '108']}; {'id': '98', 'type': 'call', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'get_model'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'list_splat', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '108', 'type': 'for_in_clause', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'deps'}, {'id': '111', 'type': 'else_clause', 'children': ['112']}; {'id': '112', 'type': 'block', 'children': ['113']}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'deps'}; {'id': '116', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '117', 'type': 'for_statement', 'children': ['118', '119', '134']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'itertools'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'chain'}, {'id': '123', 'type': 'argument_list', 'children': ['124', '129']}; {'id': '124', 'type': 'attribute', 'children': ['125', '128']}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': '_meta'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '129', 'type': 'attribute', 'children': ['130', '133']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': '_meta'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'many_to_many'}; {'id': '134', 'type': 'block', 'children': ['135']}, {'id': '135', 'type': 'if_statement', 'children': ['136', '151']}; {'id': '136', 'type': 'boolean_operator', 'children': ['137', '144'], 'value': 'and'}, {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '139', 'type': 'argument_list', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'rel'}, {'id': '143', 'type': 'string', 'children': [], 'value': "'to'"}; {'id': '144', 'type': 'comparison_operator', 'children': ['145', '150'], 'value': '!='}, {'id': '145', 'type': 'attribute', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'rel'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'to'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'model'}, {'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': 'deps'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'attribute', 'children': ['159', '162']}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'rel'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'to'}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'call', 'children': ['165', '168']}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'model_dependencies'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}, {'id': '169', 'type': 'tuple', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'deps'}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'call', 'children': ['174', '177']}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'model_dependencies'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '177', 'type': 'argument_list', 'children': []}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'assignment', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'model_list'}, {'id': '181', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '182', 'type': 'while_statement', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'model_dependencies'}; {'id': '184', 'type': 'block', 'children': ['185', '189', '193', '258', '304']}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'skipped'}; {'id': '188', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'changed'}; {'id': '192', 'type': 'False', 'children': []}, {'id': '193', 'type': 'while_statement', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'model_dependencies'}, {'id': '195', 'type': 'block', 'children': ['196', '206', '210', '233']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'assignment', 'children': ['198', '201']}; {'id': '198', 'type': 'pattern_list', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'deps'}, {'id': '201', 'type': 'call', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'model_dependencies'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '205', 'type': 'argument_list', 'children': []}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}, {'id': '207', 'type': 'assignment', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'found'}, {'id': '209', 'type': 'True', 'children': []}; {'id': '210', 'type': 'for_statement', 'children': ['211', '212', '224']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'candidate'}; {'id': '212', 'type': 'generator_expression', 'children': ['213', '221']}, {'id': '213', 'type': 'parenthesized_expression', 'children': ['214'], 'value': '()'}; {'id': '214', 'type': 'boolean_operator', 'children': ['215', '218'], 'value': 'or'}, {'id': '215', 'type': 'comparison_operator', 'children': ['216', '217'], 'value': 'not'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'models'}; {'id': '218', 'type': 'comparison_operator', 'children': ['219', '220'], 'value': 'in'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'model_list'}, {'id': '221', 'type': 'for_in_clause', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'deps'}; {'id': '224', 'type': 'block', 'children': ['225']}, {'id': '225', 'type': 'if_statement', 'children': ['226', '228']}; {'id': '226', 'type': 'not_operator', 'children': ['227']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'candidate'}; {'id': '228', 'type': 'block', 'children': ['229']}, {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'assignment', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'found'}; {'id': '232', 'type': 'False', 'children': []}, {'id': '233', 'type': 'if_statement', 'children': ['234', '235', '247']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'found'}, {'id': '235', 'type': 'block', 'children': ['236', '243']}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}, {'id': '237', 'type': 'call', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'model_list'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'assignment', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'changed'}; {'id': '246', 'type': 'True', 'children': []}, {'id': '247', 'type': 'else_clause', 'children': ['248']}; {'id': '248', 'type': 'block', 'children': ['249']}, {'id': '249', 'type': 'expression_statement', 'children': ['250']}; {'id': '250', 'type': 'call', 'children': ['251', '254']}, {'id': '251', 'type': 'attribute', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'skipped'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '254', 'type': 'argument_list', 'children': ['255']}, {'id': '255', 'type': 'tuple', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'deps'}; {'id': '258', 'type': 'if_statement', 'children': ['259', '261']}, {'id': '259', 'type': 'not_operator', 'children': ['260']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'changed'}, {'id': '261', 'type': 'block', 'children': ['262']}; {'id': '262', 'type': 'raise_statement', 'children': ['263']}, {'id': '263', 'type': 'call', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'CommandError'}, {'id': '265', 'type': 'argument_list', 'children': ['266']}; {'id': '266', 'type': 'binary_operator', 'children': ['267', '268'], 'value': '%'}, {'id': '267', 'type': 'string', 'children': [], 'value': '"Can\'t resolve dependencies for %s in serialized app list."'}; {'id': '268', 'type': 'call', 'children': ['269', '272']}, {'id': '269', 'type': 'attribute', 'children': ['270', '271']}; {'id': '270', 'type': 'string', 'children': [], 'value': "', '"}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '272', 'type': 'generator_expression', 'children': ['273', '286']}, {'id': '273', 'type': 'binary_operator', 'children': ['274', '275'], 'value': '%'}; {'id': '274', 'type': 'string', 'children': [], 'value': "'%s.%s'"}, {'id': '275', 'type': 'tuple', 'children': ['276', '281']}; {'id': '276', 'type': 'attribute', 'children': ['277', '280']}, {'id': '277', 'type': 'attribute', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': '_meta'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'app_label'}, {'id': '281', 'type': 'attribute', 'children': ['282', '285']}; {'id': '282', 'type': 'attribute', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': '_meta'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'object_name'}; {'id': '286', 'type': 'for_in_clause', 'children': ['287', '290']}, {'id': '287', 'type': 'pattern_list', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'deps'}; {'id': '290', 'type': 'call', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '292', 'type': 'argument_list', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'skipped'}; {'id': '294', 'type': 'keyword_argument', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '296', 'type': 'lambda', 'children': ['297', '299']}, {'id': '297', 'type': 'lambda_parameters', 'children': ['298']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '299', 'type': 'attribute', 'children': ['300', '303']}; {'id': '300', 'type': 'subscript', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '302', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '304', 'type': 'expression_statement', 'children': ['305']}, {'id': '305', 'type': 'assignment', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'model_dependencies'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'skipped'}; {'id': '308', 'type': 'expression_statement', 'children': ['309']}, {'id': '309', 'type': 'assignment', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'sorted_results'}, {'id': '311', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '312', 'type': 'for_statement', 'children': ['313', '314', '315']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'model_list'}, {'id': '315', 'type': 'block', 'children': ['316']}; {'id': '316', 'type': 'expression_statement', 'children': ['317']}, {'id': '317', 'type': 'call', 'children': ['318', '321']}; {'id': '318', 'type': 'attribute', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'sorted_results'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '321', 'type': 'argument_list', 'children': ['322']}; {'id': '322', 'type': 'subscript', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'objs_by_model'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '325', 'type': 'return_statement', 'children': ['326']} | def sort_dependencies(objects):
from django.db.models import get_model
model_dependencies = []
models = set()
model_list = set()
objs_by_model = defaultdict(list)
for o in objects:
model = o.__class__
objs_by_model[model].append(o)
model_list.add(model)
for model in model_list:
models.add(model)
if hasattr(model, 'natural_key'):
deps = getattr(model.natural_key, 'dependencies', [])
if deps:
deps = [get_model(*d.split('.')) for d in deps]
else:
deps = []
for field in itertools.chain(model._meta.fields, model._meta.many_to_many):
if hasattr(field.rel, 'to') and field.rel.to != model:
deps.append(field.rel.to)
model_dependencies.append((model, deps))
model_dependencies.reverse()
model_list = []
while model_dependencies:
skipped = []
changed = False
while model_dependencies:
model, deps = model_dependencies.pop()
found = True
for candidate in ((d not in models or d in model_list) for d in deps):
if not candidate:
found = False
if found:
model_list.append(model)
changed = True
else:
skipped.append((model, deps))
if not changed:
raise CommandError("Can't resolve dependencies for %s in serialized app list." %
', '.join('%s.%s' % (model._meta.app_label, model._meta.object_name)
for model, deps in sorted(skipped, key=lambda obj: obj[0].__name__))
)
model_dependencies = skipped
sorted_results = []
for model in model_list:
sorted_results.extend(objs_by_model[model])
return sorted_results |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_languages'}, {'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': 'order'}, {'id': '7', 'type': 'attribute', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'Qt'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'AscendingOrder'}; {'id': '10', 'type': 'block', 'children': ['11', '17', '40']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'beginResetModel'}; {'id': '16', 'type': 'argument_list', 'children': []}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': '__languages'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '28', '37']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': '__languages'}; {'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '30', 'type': 'lambda', 'children': ['31', '33']}, {'id': '31', 'type': 'lambda_parameters', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '33', 'type': 'parenthesized_expression', 'children': ['34'], 'value': '()'}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'endResetModel'}, {'id': '45', 'type': 'argument_list', 'children': []} | def sort_languages(self, order=Qt.AscendingOrder):
self.beginResetModel()
self.__languages = sorted(self.__languages, key=lambda x: (x.name), reverse=order)
self.endResetModel() |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'fmt_pairs'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'indent'}, {'id': '7', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort_key'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '25', '31', '38', '48', '58', '79']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'lengths'}, {'id': '15', 'type': 'list_comprehension', 'children': ['16', '22']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'subscript', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '21', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '22', 'type': 'for_in_clause', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '25', 'type': 'if_statement', 'children': ['26', '28']}; {'id': '26', 'type': 'not_operator', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'lengths'}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'return_statement', 'children': ['30']}; {'id': '30', 'type': 'string', 'children': [], 'value': "''"}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'longest'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'lengths'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '43', 'type': 'argument_list', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'sort_key'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'formatter'}, {'id': '51', 'type': 'binary_operator', 'children': ['52', '53'], 'value': '%'}; {'id': '52', 'type': 'string', 'children': [], 'value': "'%s{: <%d} {}'"}, {'id': '53', 'type': 'tuple', 'children': ['54', '57']}; {'id': '54', 'type': 'binary_operator', 'children': ['55', '56'], 'value': '*'}, {'id': '55', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'indent'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'longest'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'string'}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'list_comprehension', 'children': ['67', '74']}, {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'formatter'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '71', 'type': 'argument_list', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '74', 'type': 'for_in_clause', 'children': ['75', '78']}, {'id': '75', 'type': 'pattern_list', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '79', 'type': 'return_statement', 'children': ['80']} | def fmt_pairs(obj, indent=4, sort_key=None):
lengths = [len(x[0]) for x in obj]
if not lengths:
return ''
longest = max(lengths)
obj = sorted(obj, key=sort_key)
formatter = '%s{: <%d} {}' % (' ' * indent, longest)
string = '\n'.join([formatter.format(k, v) for k, v in obj])
return string |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'serialize'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'as_dict'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '25', '48', '64', '88']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'files'}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '19', '20']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'string', 'children': [], 'value': "'files'"}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '24', 'type': 'argument_list', 'children': []}, {'id': '25', 'type': 'if_statement', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'as_dict'}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'return_statement', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '31', 'type': 'generator_expression', 'children': ['32', '39']}; {'id': '32', 'type': 'tuple', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'to_dict'}; {'id': '38', 'type': 'argument_list', 'children': []}, {'id': '39', 'type': 'for_in_clause', 'children': ['40', '43']}; {'id': '40', 'type': 'pattern_list', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'files'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'items'}, {'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': 'data'}, {'id': '51', 'type': 'generator_expression', 'children': ['52', '57']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'to_dict'}; {'id': '56', 'type': 'argument_list', 'children': []}, {'id': '57', 'type': 'for_in_clause', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'files'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '63', 'type': 'argument_list', 'children': []}; {'id': '64', 'type': 'if_statement', 'children': ['65', '69', '78']}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'callable'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'return_statement', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '73', 'type': 'argument_list', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '78', 'type': 'elif_clause', 'children': ['79', '82']}, {'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': 'is'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '81', 'type': 'True', 'children': []}; {'id': '82', 'type': 'block', 'children': ['83']}, {'id': '83', 'type': 'return_statement', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '88', 'type': 'return_statement', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '91', 'type': 'argument_list', 'children': ['92']} | def serialize(self, as_dict=False, sort=None):
files = getattr(self, 'files', self.run())
if as_dict:
return dict((fn, p.to_dict()) for fn, p in files.items())
data = (p.to_dict() for p in files.values())
if callable(sort):
return sorted(data, key=sort)
elif sort is True:
return sorted(data)
return list(data) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'iteritems'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '28']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'sorted_data'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '11', 'type': 'argument_list', 'children': ['12', '19', '22', '25']}; {'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': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '18', 'type': 'argument_list', 'children': []}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'cmp'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '28', 'type': 'for_statement', 'children': ['29', '32', '33']}, {'id': '29', 'type': 'pattern_list', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'sorted_data'}, {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'yield', 'children': ['36']}; {'id': '36', 'type': 'expression_list', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'k'} | def iteritems(self):
sorted_data = sorted(self.data.iteritems(), self.cmp, self.key,
self.reverse)
for k,v in sorted_data:
yield k,v |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_posts'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'num'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'private'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '21', '37', '54', '63']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'posts'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'posts'}, {'id': '21', 'type': 'if_statement', 'children': ['22', '24']}; {'id': '22', 'type': 'not_operator', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'private'}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'posts'}; {'id': '28', 'type': 'list_comprehension', 'children': ['29', '30', '33']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'post'}; {'id': '30', 'type': 'for_in_clause', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'post'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'posts'}, {'id': '33', 'type': 'if_clause', 'children': ['34']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'post'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'public'}, {'id': '37', 'type': 'if_statement', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'posts'}, {'id': '43', 'type': 'list_comprehension', 'children': ['44', '45', '48']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'post'}, {'id': '45', 'type': 'for_in_clause', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'post'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'posts'}; {'id': '48', 'type': 'if_clause', 'children': ['49']}, {'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'in'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'post'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'tags'}; {'id': '54', 'type': 'if_statement', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'num'}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'return_statement', 'children': ['58']}; {'id': '58', 'type': 'subscript', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'posts'}; {'id': '60', 'type': 'slice', 'children': ['61', '62']}, {'id': '61', 'type': 'colon', 'children': []}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'num'}, {'id': '63', 'type': 'return_statement', 'children': ['64']} | def get_posts(self, num=None, tag=None, private=False):
posts = self.posts
if not private:
posts = [post for post in posts if post.public]
if tag:
posts = [post for post in posts if tag in post.tags]
if num:
return posts[:num]
return posts |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_sort_function'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '5', 'type': 'block', 'children': ['6', '26', '71']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'stable'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '11', 'type': 'generator_expression', 'children': ['12', '23']}; {'id': '12', 'type': 'tuple', 'children': ['13', '16']}, {'id': '13', 'type': 'subscript', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '15', 'type': 'string', 'children': [], 'value': "'key'"}; {'id': '16', 'type': 'conditional_expression', 'children': ['17', '19', '22'], 'value': 'if'}, {'id': '17', 'type': 'unary_operator', 'children': ['18'], 'value': '-'}; {'id': '18', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '19', 'type': 'subscript', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '21', 'type': 'string', 'children': [], 'value': "'reverse'"}; {'id': '22', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '23', 'type': 'for_in_clause', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '26', 'type': 'function_definition', 'children': ['27', '28', '31']}, {'id': '27', 'type': 'function_name', 'children': [], 'value': 'sort_function'}; {'id': '28', 'type': 'parameters', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '31', 'type': 'block', 'children': ['32', '69']}; {'id': '32', 'type': 'for_statement', 'children': ['33', '36', '37']}, {'id': '33', 'type': 'pattern_list', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'direction'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'stable'}, {'id': '37', 'type': 'block', 'children': ['38', '60']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'cmp'}, {'id': '43', 'type': 'argument_list', 'children': ['44', '52']}; {'id': '44', 'type': 'conditional_expression', 'children': ['45', '50', '51'], 'value': 'if'}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '52', 'type': 'conditional_expression', 'children': ['53', '58', '59'], 'value': 'if'}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '55', 'type': 'argument_list', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '60', 'type': 'if_statement', 'children': ['61', '64']}, {'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': '!='}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '63', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'return_statement', 'children': ['66']}; {'id': '66', 'type': 'binary_operator', 'children': ['67', '68'], 'value': '*'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'direction'}, {'id': '69', 'type': 'return_statement', 'children': ['70']}; {'id': '70', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '71', 'type': 'return_statement', 'children': ['72']} | def get_sort_function(order):
stable = tuple((d['key'], -1 if d['reverse'] else 1) for d in order)
def sort_function(a, b):
for name, direction in stable:
v = cmp(getattr(a, name) if a else a, getattr(b, name) if b else b)
if v != 0:
return v * direction
return 0
return sort_function |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_proxy_model'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '6', 'type': 'block', 'children': ['7', '14', '21', '32']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'proxy'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'ReftrackSortFilterModel'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'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': 'proxy'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'setSourceModel'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '28']}, {'id': '23', 'type': 'attribute', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'rowsInserted'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'connect'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'sort_model'}; {'id': '32', 'type': 'return_statement', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'proxy'} | def create_proxy_model(self, model):
proxy = ReftrackSortFilterModel(self)
proxy.setSourceModel(model)
model.rowsInserted.connect(self.sort_model)
return proxy |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_model'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'list_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '9', 'type': 'block', 'children': ['10', '19', '28', '37']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'call', 'children': ['12', '17']}; {'id': '12', 'type': 'attribute', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'proxy'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'integer', 'children': [], 'value': '17'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'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': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'proxy'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '35']}; {'id': '30', 'type': 'attribute', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'proxy'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '44']}, {'id': '39', 'type': 'attribute', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'proxy'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'integer', 'children': [], 'value': '0'} | def sort_model(self, *args, **kwargs):
self.proxy.sort(17)
self.proxy.sort(2)
self.proxy.sort(1)
self.proxy.sort(0) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'prepare_value'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '6', 'type': 'block', 'children': ['7', '41']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '15']}; {'id': '8', 'type': 'boolean_operator', 'children': ['9', '12'], 'value': 'and'}, {'id': '9', 'type': 'comparison_operator', 'children': ['10', '11'], 'value': 'is'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'required'}, {'id': '15', 'type': 'block', 'children': ['16', '25']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'choices'}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'choices'}, {'id': '25', 'type': 'if_statement', 'children': ['26', '32']}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '31'], 'value': '=='}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'choices'}, {'id': '31', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '32', 'type': 'block', 'children': ['33']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '36', 'type': 'subscript', 'children': ['37', '40']}, {'id': '37', 'type': 'subscript', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'choices'}, {'id': '39', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '40', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '41', 'type': 'return_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '50']}, {'id': '43', 'type': 'attribute', 'children': ['44', '49']}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'super'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'TemplateChoiceField'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'prepare_value'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'value'} | def prepare_value(self, value):
if value is None and self.required:
choices =list(self.choices)
if len(choices) == 1:
value = choices[0][0]
return super(TemplateChoiceField, self).prepare_value(value) |
{'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': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '15', '39']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'call', 'children': ['8', '13']}; {'id': '8', 'type': 'attribute', 'children': ['9', '12']}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': '_log'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'string', 'children': [], 'value': "'Sorting responses by priority'"}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': '_responses'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}; {'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', '36']}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '35']}; {'id': '30', 'type': 'attribute', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': '_responses'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '38', 'type': 'True', 'children': []}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'sorted'} | def _sort(self):
self._log.debug('Sorting responses by priority')
self._responses = OrderedDict(sorted(list(self._responses.items()), reverse=True))
self.sorted = True |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'csv_row_to_transaction'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'source_encoding'}; {'id': '8', 'type': 'string', 'children': [], 'value': '"latin1"'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'date_format'}, {'id': '11', 'type': 'string', 'children': [], 'value': '"%d-%m-%Y"'}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'thousand_sep'}; {'id': '14', 'type': 'string', 'children': [], 'value': '"."'}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'decimal_sep'}, {'id': '17', 'type': 'string', 'children': [], 'value': '","'}; {'id': '18', 'type': 'block', 'children': ['19', '28', '37', '46', '56', '65', '74']}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '27']}, {'id': '21', 'type': 'pattern_list', 'children': ['22', '23', '24', '25', '26']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'xfer'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'posted'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'amount'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'total'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'xfer'}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'Parse'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'date'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'xfer'}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'posted'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'Parse'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'posted'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'Parse'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'to_utf8'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'source_encoding'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'amount'}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'Parse'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'money'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'amount'}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'Parse'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'money'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '74', 'type': 'return_statement', 'children': ['75']}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'Transaction'}, {'id': '77', 'type': 'argument_list', 'children': ['78', '79', '80', '81', '82', '83']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'xfer'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'posted'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'amount'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'total'} | def csv_row_to_transaction(index, row, source_encoding="latin1",
date_format="%d-%m-%Y", thousand_sep=".", decimal_sep=","):
xfer, posted, message, amount, total = row
xfer = Parse.date(xfer)
posted = Parse.date(posted)
message = Parse.to_utf8(message, source_encoding)
amount = Parse.money(amount)
total = Parse.money(total)
return Transaction(index, xfer, posted, message, amount, total) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'csv_to_transactions'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'handle'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'source_encoding'}, {'id': '7', 'type': 'string', 'children': [], 'value': '"latin1"'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'date_format'}; {'id': '10', 'type': 'string', 'children': [], 'value': '"%d-%m-%Y"'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'thousand_sep'}, {'id': '13', 'type': 'string', 'children': [], 'value': '"."'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'decimal_sep'}; {'id': '16', 'type': 'string', 'children': [], 'value': '","'}, {'id': '17', 'type': 'block', 'children': ['18', '24', '39', '61']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'trans'}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'Transactions'}, {'id': '23', 'type': 'argument_list', 'children': []}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'rows'}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'csv'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'reader'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '33', '36']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'handle'}, {'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'delimiter'}, {'id': '35', 'type': 'string', 'children': [], 'value': '";"'}; {'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'quotechar'}; {'id': '38', 'type': 'string', 'children': [], 'value': '"\\""'}, {'id': '39', 'type': 'for_statement', 'children': ['40', '43', '47']}; {'id': '40', 'type': 'pattern_list', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'rows'}, {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'trans'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'Parse'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'csv_row_to_transaction'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '61', 'type': 'return_statement', 'children': ['62']} | def csv_to_transactions(handle, source_encoding="latin1",
date_format="%d-%m-%Y", thousand_sep=".", decimal_sep=","):
trans = Transactions()
rows = csv.reader(handle, delimiter=";", quotechar="\"")
for index, row in enumerate(rows):
trans.append(Parse.csv_row_to_transaction(index, row))
return trans |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'filterAcceptsRow'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'parentindex'}, {'id': '7', 'type': 'block', 'children': ['8', '24', '49', '60', '69']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '21']}, {'id': '9', 'type': 'not_operator', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '18']}, {'id': '11', 'type': 'attribute', 'children': ['12', '17']}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'super'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'ReftrackSortFilterModel'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'filterAcceptsRow'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'parentindex'}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'return_statement', 'children': ['23']}, {'id': '23', 'type': 'False', 'children': []}; {'id': '24', 'type': 'if_statement', 'children': ['25', '30', '39']}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'parentindex'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'isValid'}, {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'parentindex'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '38', 'type': 'argument_list', 'children': []}, {'id': '39', 'type': 'else_clause', 'children': ['40']}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '44', 'type': 'call', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'sourceModel'}; {'id': '48', 'type': 'argument_list', 'children': []}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '58', '59']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '18'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'parentindex'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'reftrack'}, {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'REFTRACK_OBJECT_ROLE'}, {'id': '69', 'type': 'if_statement', 'children': ['70', '72', '75']}; {'id': '70', 'type': 'not_operator', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'reftrack'}; {'id': '72', 'type': 'block', 'children': ['73']}, {'id': '73', 'type': 'return_statement', 'children': ['74']}; {'id': '74', 'type': 'True', 'children': []}, {'id': '75', 'type': 'else_clause', 'children': ['76']}; {'id': '76', 'type': 'block', 'children': ['77']}, {'id': '77', 'type': 'return_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'filter_accept_reftrack'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'reftrack'} | def filterAcceptsRow(self, row, parentindex):
if not super(ReftrackSortFilterModel, self).filterAcceptsRow(row, parentindex):
return False
if parentindex.isValid():
m = parentindex.model()
else:
m = self.sourceModel()
i = m.index(row, 18, parentindex)
reftrack = i.data(REFTRACK_OBJECT_ROLE)
if not reftrack:
return True
else:
return self.filter_accept_reftrack(reftrack) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_grid_data'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'file_list'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'data_type'}, {'id': '7', 'type': 'string', 'children': [], 'value': '"binary"'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '10', 'type': 'True', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'delim'}, {'id': '13', 'type': 'string', 'children': [], 'value': '" "'}; {'id': '14', 'type': 'block', 'children': ['15', '54', '64', '72', '218']}, {'id': '15', 'type': 'if_statement', 'children': ['16', '23', '29']}; {'id': '16', 'type': 'not_operator', 'children': ['17']}, {'id': '17', 'type': 'comparison_operator', 'children': ['18', '22'], 'value': 'is'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'file_list'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'file_list'}, {'id': '27', 'type': 'list', 'children': ['28'], 'value': '[file_list]'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'file_list'}, {'id': '29', 'type': 'elif_clause', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'file_list'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '40', 'type': 'lambda', 'children': ['41', '43']}, {'id': '41', 'type': 'lambda_parameters', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52', '53']}, {'id': '51', 'type': 'string', 'children': [], 'value': '"[^0-9]"'}; {'id': '52', 'type': 'string', 'children': [], 'value': '""'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'world_size'}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'get_world_dimensions'}, {'id': '59', 'type': 'argument_list', 'children': ['60', '63']}; {'id': '60', 'type': 'subscript', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'file_list'}; {'id': '62', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'delim'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'initialize_grid'}, {'id': '69', 'type': 'argument_list', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'world_size'}, {'id': '71', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '72', 'type': 'for_statement', 'children': ['73', '74', '75']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'file_list'}, {'id': '75', 'type': 'block', 'children': ['76', '83', '91', '212']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'infile'}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'open'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'infile'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'readlines'}; {'id': '90', 'type': 'argument_list', 'children': []}, {'id': '91', 'type': 'for_statement', 'children': ['92', '93', '99']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'subscript', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'world_size'}; {'id': '98', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '99', 'type': 'block', 'children': ['100', '117']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '105']}; {'id': '102', 'type': 'subscript', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '105', 'type': 'call', 'children': ['106', '115']}; {'id': '106', 'type': 'attribute', 'children': ['107', '114']}, {'id': '107', 'type': 'call', 'children': ['108', '113']}; {'id': '108', 'type': 'attribute', 'children': ['109', '112']}, {'id': '109', 'type': 'subscript', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'lines'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '113', 'type': 'argument_list', 'children': []}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'delim'}, {'id': '117', 'type': 'for_statement', 'children': ['118', '119', '125']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'subscript', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'world_size'}; {'id': '124', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '125', 'type': 'block', 'children': ['126', '201']}; {'id': '126', 'type': 'if_statement', 'children': ['127', '130', '145', '161', '177', '193']}, {'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': '=='}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'data_type'}, {'id': '129', 'type': 'string', 'children': [], 'value': '"binary"'}; {'id': '130', 'type': 'block', 'children': ['131']}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '134', 'type': 'call', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'bin'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}, {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'subscript', 'children': ['141', '144']}, {'id': '141', 'type': 'subscript', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'lines'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '145', 'type': 'elif_clause', 'children': ['146', '149']}; {'id': '146', 'type': 'comparison_operator', 'children': ['147', '148'], 'value': '=='}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'data_type'}; {'id': '148', 'type': 'string', 'children': [], 'value': '"float"'}, {'id': '149', 'type': 'block', 'children': ['150']}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'subscript', 'children': ['157', '160']}, {'id': '157', 'type': 'subscript', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'lines'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '161', 'type': 'elif_clause', 'children': ['162', '165']}; {'id': '162', 'type': 'comparison_operator', 'children': ['163', '164'], 'value': '=='}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'data_type'}; {'id': '164', 'type': 'string', 'children': [], 'value': '"int"'}, {'id': '165', 'type': 'block', 'children': ['166']}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'assignment', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'subscript', 'children': ['173', '176']}, {'id': '173', 'type': 'subscript', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'lines'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '177', 'type': 'elif_clause', 'children': ['178', '181']}; {'id': '178', 'type': 'comparison_operator', 'children': ['179', '180'], 'value': '=='}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'data_type'}; {'id': '180', 'type': 'string', 'children': [], 'value': '"string"'}, {'id': '181', 'type': 'block', 'children': ['182']}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '185', 'type': 'call', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'subscript', 'children': ['189', '192']}, {'id': '189', 'type': 'subscript', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'lines'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '193', 'type': 'else_clause', 'children': ['194']}; {'id': '194', 'type': 'block', 'children': ['195', '200']}, {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'call', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '198', 'type': 'argument_list', 'children': ['199']}, {'id': '199', 'type': 'string', 'children': [], 'value': '"Unsupported data_type passed to load_grid"'}; {'id': '200', 'type': 'return_statement', 'children': []}, {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'call', 'children': ['203', '210']}, {'id': '203', 'type': 'attribute', 'children': ['204', '209']}; {'id': '204', 'type': 'subscript', 'children': ['205', '208']}, {'id': '205', 'type': 'subscript', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}, {'id': '213', 'type': 'call', 'children': ['214', '217']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'infile'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'close'}, {'id': '217', 'type': 'argument_list', 'children': []}; {'id': '218', 'type': 'return_statement', 'children': ['219']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'data'} | def load_grid_data(file_list, data_type="binary", sort=True, delim=" "):
if not type(file_list) is list:
file_list = [file_list]
elif sort:
file_list.sort(key=lambda f: int(re.sub("[^0-9]", "", f)))
world_size = get_world_dimensions(file_list[0], delim)
data = initialize_grid(world_size, [])
for f in file_list:
infile = open(f)
lines = infile.readlines()
for i in range(world_size[1]):
lines[i] = lines[i].strip().split(delim)
for j in range(world_size[0]):
if data_type == "binary":
val = bin(int(lines[i][j]))
elif data_type == "float":
val = float(lines[i][j])
elif data_type == "int":
val = int(lines[i][j])
elif data_type == "string":
val = str(lines[i][j])
else:
print("Unsupported data_type passed to load_grid")
return
data[i][j].append(val)
infile.close()
return data |
{'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': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '113', '119', '156']}; {'id': '6', 'type': 'for_statement', 'children': ['7', '10', '17']}, {'id': '7', 'type': 'pattern_list', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'priority'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'triggers'}; {'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': '_triggers'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '16', 'type': 'argument_list', 'children': []}, {'id': '17', 'type': 'block', 'children': ['18', '34', '46', '59', '81', '103']}; {'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': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': '_log'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'string', 'children': [], 'value': "'Sorting priority {priority} triggers'"}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'priority'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'priority'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'atomics'}, {'id': '37', 'type': 'list_comprehension', 'children': ['38', '39', '42']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'trigger'}, {'id': '39', 'type': 'for_in_clause', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'trigger'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'triggers'}; {'id': '42', 'type': 'if_clause', 'children': ['43']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'trigger'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'pattern_is_atomic'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'wildcards'}, {'id': '49', 'type': 'list_comprehension', 'children': ['50', '51', '54']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'trigger'}, {'id': '51', 'type': 'for_in_clause', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'trigger'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'triggers'}; {'id': '54', 'type': 'if_clause', 'children': ['55']}, {'id': '55', 'type': 'not_operator', 'children': ['56']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'trigger'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'pattern_is_atomic'}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'atomics'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '66', '78']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'atomics'}; {'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '68', 'type': 'lambda', 'children': ['69', '71']}, {'id': '69', 'type': 'lambda_parameters', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'trigger'}, {'id': '71', 'type': 'tuple', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'trigger'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'pattern_words'}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'trigger'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'pattern_len'}; {'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '80', 'type': 'True', 'children': []}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'wildcards'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '88', '100']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'wildcards'}; {'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '90', 'type': 'lambda', 'children': ['91', '93']}, {'id': '91', 'type': 'lambda_parameters', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'trigger'}, {'id': '93', 'type': 'tuple', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'trigger'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'pattern_words'}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'trigger'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'pattern_len'}; {'id': '100', 'type': 'keyword_argument', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '102', 'type': 'True', 'children': []}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '110']}, {'id': '105', 'type': 'subscript', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': '_triggers'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'priority'}; {'id': '110', 'type': 'binary_operator', 'children': ['111', '112'], 'value': '+'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'atomics'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'wildcards'}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': '_sorted_triggers'}; {'id': '118', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '119', 'type': 'for_statement', 'children': ['120', '121', '142']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'triggers'}, {'id': '121', 'type': 'list_comprehension', 'children': ['122', '127']}; {'id': '122', 'type': 'subscript', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': '_triggers'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'priority'}, {'id': '127', 'type': 'for_in_clause', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'priority'}, {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '131', 'type': 'argument_list', 'children': ['132', '139']}; {'id': '132', 'type': 'call', 'children': ['133', '138']}, {'id': '133', 'type': 'attribute', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': '_triggers'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '138', 'type': 'argument_list', 'children': []}, {'id': '139', 'type': 'keyword_argument', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '141', 'type': 'True', 'children': []}; {'id': '142', 'type': 'block', 'children': ['143']}, {'id': '143', 'type': 'for_statement', 'children': ['144', '145', '146']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'trigger'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'triggers'}; {'id': '146', 'type': 'block', 'children': ['147']}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'call', 'children': ['149', '154']}, {'id': '149', 'type': 'attribute', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': '_sorted_triggers'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'trigger'}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '161', 'type': 'True', 'children': []} | def sort(self):
for priority, triggers in self._triggers.items():
self._log.debug('Sorting priority {priority} triggers'.format(priority=priority))
atomics = [trigger for trigger in triggers if trigger.pattern_is_atomic]
wildcards = [trigger for trigger in triggers if not trigger.pattern_is_atomic]
atomics = sorted(atomics, key=lambda trigger: (trigger.pattern_words, trigger.pattern_len), reverse=True)
wildcards = sorted(wildcards, key=lambda trigger: (trigger.pattern_words, trigger.pattern_len),
reverse=True)
self._triggers[priority] = atomics + wildcards
self._sorted_triggers = []
for triggers in [self._triggers[priority] for priority in sorted(self._triggers.keys(), reverse=True)]:
for trigger in triggers:
self._sorted_triggers.append(trigger)
self.sorted = True |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'log_message'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '7', 'type': 'block', 'children': ['8', '36', '44', '56']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '14', '21']}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '11', 'type': 'argument_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'user'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'SeshetUser'}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'nick'}, {'id': '21', 'type': 'elif_clause', 'children': ['22', '28']}; {'id': '22', 'type': 'not_operator', 'children': ['23']}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '25', 'type': 'argument_list', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'user'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'IRCstr'}; {'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': 'user'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'IRCstr'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'utcnow'}, {'id': '43', 'type': 'argument_list', 'children': []}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '51']}; {'id': '46', 'type': 'attribute', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'message_log'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'tuple', 'children': ['53', '54', '55']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'user'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '56', 'type': 'while_statement', 'children': ['57', '67']}, {'id': '57', 'type': 'comparison_operator', 'children': ['58', '64'], 'value': '>'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'message_log'}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': '_log_size'}, {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'delete_statement', 'children': ['69']}, {'id': '69', 'type': 'subscript', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'message_log'}, {'id': '73', 'type': 'integer', 'children': [], 'value': '0'} | def log_message(self, user, message):
if isinstance(user, SeshetUser):
user = user.nick
elif not isinstance(user, IRCstr):
user = IRCstr(user)
time = datetime.utcnow()
self.message_log.append((time, user, message))
while len(self.message_log) > self._log_size:
del self.message_log[0] |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '22']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_item'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'icon'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'permission'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'active_regex'}, {'id': '21', 'type': 'None', 'children': []}; {'id': '22', 'type': 'block', 'children': ['23', '40', '46', '50', '127', '140', '157']}, {'id': '23', 'type': 'if_statement', 'children': ['24', '29']}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '28'], 'value': 'is'}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'root_item'}; {'id': '28', 'type': 'None', 'children': []}, {'id': '29', 'type': 'block', 'children': ['30']}; {'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': 'root_item'}, {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'MenuItem'}, {'id': '37', 'type': 'argument_list', 'children': ['38', '39']}; {'id': '38', 'type': 'string', 'children': [], 'value': "'ROOT'"}, {'id': '39', 'type': 'string', 'children': [], 'value': "'ROOT'"}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'root_item'}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'root_item'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'current_path'}, {'id': '49', 'type': 'string', 'children': [], 'value': "''"}; {'id': '50', 'type': 'for_statement', 'children': ['51', '52', '63']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '52', 'type': 'subscript', 'children': ['53', '59']}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '59', 'type': 'slice', 'children': ['60', '61']}; {'id': '60', 'type': 'colon', 'children': []}, {'id': '61', 'type': 'unary_operator', 'children': ['62'], 'value': '-'}; {'id': '62', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '63', 'type': 'block', 'children': ['64', '69', '86', '95', '123']}; {'id': '64', 'type': 'if_statement', 'children': ['65', '67']}, {'id': '65', 'type': 'not_operator', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'continue_statement', 'children': []}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'current_path'}; {'id': '72', 'type': 'binary_operator', 'children': ['73', '74'], 'value': '+'}, {'id': '73', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '74', 'type': 'call', 'children': ['75', '84']}, {'id': '75', 'type': 'attribute', 'children': ['76', '83']}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'string', 'children': [], 'value': "'{}/{}'"}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'current_path'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'new_root'}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'root_item'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'child_by_code'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '95', 'type': 'if_statement', 'children': ['96', '98']}; {'id': '96', 'type': 'not_operator', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'new_root'}; {'id': '98', 'type': 'block', 'children': ['99', '116']}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'new_root'}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'MenuItem'}; {'id': '104', 'type': 'argument_list', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'current_path'}; {'id': '106', 'type': 'keyword_argument', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '108', 'type': 'call', 'children': ['109', '115']}, {'id': '109', 'type': 'attribute', 'children': ['110', '114']}; {'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': 'node'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'capitalize'}, {'id': '115', 'type': 'argument_list', 'children': []}; {'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': 'root_item'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'add_child'}, {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'new_root'}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'root_item'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'new_root'}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'new_item'}; {'id': '130', 'type': 'call', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'MenuItem'}; {'id': '132', 'type': 'argument_list', 'children': ['133', '134', '135', '136', '137', '138', '139']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'icon'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'permission'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'active_regex'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'current_item'}, {'id': '143', 'type': 'call', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'root_item'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'child_by_code'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'subscript', 'children': ['149', '155']}, {'id': '149', 'type': 'call', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '155', 'type': 'unary_operator', 'children': ['156'], 'value': '-'}; {'id': '156', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '157', 'type': 'if_statement', 'children': ['158', '159', '167']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'current_item'}, {'id': '159', 'type': 'block', 'children': ['160']}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'call', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'current_item'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'merge'}, {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'new_item'}, {'id': '167', 'type': 'else_clause', 'children': ['168']}; {'id': '168', 'type': 'block', 'children': ['169']}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'call', 'children': ['171', '174']}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'root_item'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'add_child'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'new_item'} | def add_item(self, path, name, icon=None, url=None, order=None, permission=None, active_regex=None):
if self.root_item is None:
self.root_item = MenuItem('ROOT', 'ROOT')
root_item = self.root_item
current_path = ''
for node in path.split('/')[:-1]:
if not node:
continue
current_path = '/' + '{}/{}'.format(current_path, node).strip('/')
new_root = root_item.child_by_code(node)
if not new_root:
new_root = MenuItem(current_path, name=str(node).capitalize())
root_item.add_child(new_root)
root_item = new_root
new_item = MenuItem(path, name, icon, url, order, permission, active_regex)
current_item = root_item.child_by_code(path.split('/')[-1])
if current_item:
current_item.merge(new_item)
else:
root_item.add_child(new_item) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'assist'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'project_path'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'position'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'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': '_call'}, {'id': '15', 'type': 'argument_list', 'children': ['16', '17', '18', '19', '20']}; {'id': '16', 'type': 'string', 'children': [], 'value': "'assist'"}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'project_path'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'position'} | def assist(self, project_path, source, position, filename):
return self._call('assist', project_path, source, position, filename) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_key_list'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '18', '41', '51']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '11']}, {'id': '7', 'type': 'not_operator', 'children': ['8']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'is_baked'}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'bake'}, {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'key_value_tuple'}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '31']}; {'id': '24', 'type': 'call', 'children': ['25', '30']}, {'id': '25', 'type': 'attribute', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'dct'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '30', 'type': 'argument_list', 'children': []}, {'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '33', 'type': 'lambda', 'children': ['34', '36']}; {'id': '34', 'type': 'lambda_parameters', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '36', 'type': 'subscript', 'children': ['37', '40']}, {'id': '37', 'type': 'subscript', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '39', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '40', 'type': 'string', 'children': [], 'value': "'__abs_time__'"}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'skl'}; {'id': '44', 'type': 'list_comprehension', 'children': ['45', '48']}, {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '47', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '48', 'type': 'for_in_clause', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'key_value_tuple'}, {'id': '51', 'type': 'return_statement', 'children': ['52']} | def sorted_key_list(self):
if not self.is_baked:
self.bake()
key_value_tuple = sorted(self.dct.items(),
key=lambda x: x[1]['__abs_time__'])
skl = [k[0] for k in key_value_tuple]
return skl |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_used_key_frames'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '16', '20', '48']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'skl'}, {'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': 'key_frame_list'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'sorted_key_list'}, {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'used_key_frames'}, {'id': '19', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '20', 'type': 'for_statement', 'children': ['21', '22', '23']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'kf'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'skl'}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'if_statement', 'children': ['25', '32']}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'in'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'kf'}, {'id': '27', 'type': 'subscript', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'dct'}, {'id': '31', 'type': 'string', 'children': [], 'value': "'keys'"}; {'id': '32', 'type': 'block', 'children': ['33']}, {'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': 'used_key_frames'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'tuple', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'kf'}, {'id': '41', 'type': 'subscript', 'children': ['42', '47']}; {'id': '42', 'type': 'subscript', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'dct'}; {'id': '46', 'type': 'string', 'children': [], 'value': "'keys'"}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'kf'}; {'id': '48', 'type': 'return_statement', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'used_key_frames'} | def get_used_key_frames(self):
skl = self.key_frame_list.sorted_key_list()
used_key_frames = []
for kf in skl:
if kf in self.dct['keys']:
used_key_frames.append((kf, self.dct['keys'][kf]))
return used_key_frames |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'flds_firstsort'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '5', 'type': 'block', 'children': ['6', '8', '29', '47']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'string', 'children': [], 'value': "'''\n Perform a lexsort and return the sort indices and shape as a tuple.\n '''"}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '11', 'type': 'list_comprehension', 'children': ['12', '23']}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'unique'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'subscript', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '23', 'type': 'for_in_clause', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '25', 'type': 'list', 'children': ['26', '27', '28'], 'value': "['xs', 'ys', 'zs']"}; {'id': '26', 'type': 'string', 'children': [], 'value': "'xs'"}, {'id': '27', 'type': 'string', 'children': [], 'value': "'ys'"}; {'id': '28', 'type': 'string', 'children': [], 'value': "'zs'"}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'si'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'lexsort'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'tuple', 'children': ['38', '41', '44']}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '40', 'type': 'string', 'children': [], 'value': "'z'"}, {'id': '41', 'type': 'subscript', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '43', 'type': 'string', 'children': [], 'value': "'y'"}; {'id': '44', 'type': 'subscript', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '46', 'type': 'string', 'children': [], 'value': "'x'"}, {'id': '47', 'type': 'return_statement', 'children': ['48']}; {'id': '48', 'type': 'expression_list', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'si'} | def flds_firstsort(d):
'''
Perform a lexsort and return the sort indices and shape as a tuple.
'''
shape = [ len( np.unique(d[l]) )
for l in ['xs', 'ys', 'zs'] ];
si = np.lexsort((d['z'],d['y'],d['x']));
return si,shape; |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'flds_sort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '6', 'type': 'block', 'children': ['7', '9', '31', '37', '69']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'string', 'children': [], 'value': "'''\n Sort based on position. Sort with s as a tuple of the sort\n indices and shape from first sort.\n Parameters:\n -----------\n d -- the flds/sclr data\n s -- (si, shape) sorting and shaping data from firstsort.\n '''"}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '12', 'type': 'list_comprehension', 'children': ['13', '14', '21']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '14', 'type': 'for_in_clause', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '20', 'type': 'argument_list', 'children': []}, {'id': '21', 'type': 'if_clause', 'children': ['22']}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'not'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '24', 'type': 'list', 'children': ['25', '26', '27', '28', '29', '30'], 'value': "['t', 'xs', 'ys', 'zs', 'fd', 'sd']"}, {'id': '25', 'type': 'string', 'children': [], 'value': "'t'"}; {'id': '26', 'type': 'string', 'children': [], 'value': "'xs'"}, {'id': '27', 'type': 'string', 'children': [], 'value': "'ys'"}; {'id': '28', 'type': 'string', 'children': [], 'value': "'zs'"}, {'id': '29', 'type': 'string', 'children': [], 'value': "'fd'"}; {'id': '30', 'type': 'string', 'children': [], 'value': "'sd'"}, {'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': 'si'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '37', 'type': 'for_statement', 'children': ['38', '39', '40']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '40', 'type': 'block', 'children': ['41', '56']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '46']}, {'id': '43', 'type': 'subscript', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '46', 'type': 'call', 'children': ['47', '54']}, {'id': '47', 'type': 'attribute', 'children': ['48', '53']}; {'id': '48', 'type': 'subscript', 'children': ['49', '52']}, {'id': '49', 'type': 'subscript', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'si'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'reshape'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'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': 'd'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'squeeze'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '69', 'type': 'return_statement', 'children': ['70']} | def flds_sort(d,s):
'''
Sort based on position. Sort with s as a tuple of the sort
indices and shape from first sort.
Parameters:
-----------
d -- the flds/sclr data
s -- (si, shape) sorting and shaping data from firstsort.
'''
labels = [ key for key in d.keys()
if key not in ['t', 'xs', 'ys', 'zs', 'fd', 'sd'] ];
si,shape = s;
for l in labels:
d[l] = d[l][si].reshape(shape);
d[l] = np.squeeze(d[l]);
return d; |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'read'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fname'}, {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kw'}, {'id': '7', 'type': 'block', 'children': ['8', '10', '37', '50', '324']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'string', 'children': [], 'value': "'''\n Reads an lsp output file and returns a raw dump of data,\n sectioned into quantities either as an dictionary or a typed numpy array.\n Parameters:\n -----------\n fname -- filename of thing to read\n Keyword Arguments:\n ------------------\n vprint -- Verbose printer. Used in scripts\n override -- (type, start) => A tuple of a dump type and a place to start\n in the passed file, useful to attempting to read semicorrupted\n files.\n gzip -- Read as a gzip file.\n flds/sclr Specific Arguments:\n -----------------------------\n var -- list of quantities to be read. For fields, this can consist\n of strings that include vector components, e.g., 'Ex'. If \n None (default), read all quantities.\n keep_edges -- If set to truthy, then don't remove the edges from domains before\n concatenation and don't reshape the flds data.\n sort -- If not None, sort using these indices, useful for avoiding\n resorting. If True and not an ndarray, just sort.\n first_sort -- If truthy, sort, and return the sort data for future flds\n that should have the same shape.\n keep_xs -- Keep the xs's, that is, the grid information. Usually redundant\n with x,y,z returned.\n return_array -- If set to truthy, then try to return a numpy array with a dtype.\n Requires of course that the quantities have the same shape.\n '''"}; {'id': '10', 'type': 'if_statement', 'children': ['11', '22']}, {'id': '11', 'type': 'boolean_operator', 'children': ['12', '17'], 'value': 'and'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '16', 'type': 'string', 'children': [], 'value': "'gzip'"}, {'id': '17', 'type': 'comparison_operator', 'children': ['18', '21'], 'value': '=='}; {'id': '18', 'type': 'subscript', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '20', 'type': 'string', 'children': [], 'value': "'gzip'"}, {'id': '21', 'type': 'string', 'children': [], 'value': "'guess'"}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '28']}, {'id': '25', 'type': 'subscript', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'kw'}, {'id': '27', 'type': 'string', 'children': [], 'value': "'gzip'"}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '36'], 'value': 'is'}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'search'}, {'id': '33', 'type': 'argument_list', 'children': ['34', '35']}; {'id': '34', 'type': 'string', 'children': [], 'value': "r'\\.gz$'"}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '36', 'type': 'None', 'children': []}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'openf'}; {'id': '40', 'type': 'conditional_expression', 'children': ['41', '44', '49'], 'value': 'if'}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'gzip'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '48', 'type': 'string', 'children': [], 'value': "'gzip'"}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '50', 'type': 'with_statement', 'children': ['51', '61']}, {'id': '51', 'type': 'with_clause', 'children': ['52']}; {'id': '52', 'type': 'with_item', 'children': ['53']}, {'id': '53', 'type': 'as_pattern', 'children': ['54', '59']}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'openf'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '58', 'type': 'string', 'children': [], 'value': "'rb'"}, {'id': '59', 'type': 'as_pattern_target', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'file'}, {'id': '61', 'type': 'block', 'children': ['62', '120', '136', '223', '304']}; {'id': '62', 'type': 'if_statement', 'children': ['63', '68', '111']}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'test'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'kw'}, {'id': '67', 'type': 'string', 'children': [], 'value': "'override'"}; {'id': '68', 'type': 'block', 'children': ['69', '77', '84', '91']}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '74']}, {'id': '71', 'type': 'pattern_list', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'dump'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '74', 'type': 'subscript', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '76', 'type': 'string', 'children': [], 'value': "'override'"}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'file'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'seek'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'header'}, {'id': '87', 'type': 'dictionary', 'children': ['88']}; {'id': '88', 'type': 'pair', 'children': ['89', '90']}, {'id': '89', 'type': 'string', 'children': [], 'value': "'dump_type'"}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'dump'}, {'id': '91', 'type': 'if_statement', 'children': ['92', '105']}; {'id': '92', 'type': 'boolean_operator', 'children': ['93', '99'], 'value': 'and'}, {'id': '93', 'type': 'not_operator', 'children': ['94']}; {'id': '94', 'type': 'call', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '96', 'type': 'argument_list', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '98', 'type': 'string', 'children': [], 'value': "'var'"}, {'id': '99', 'type': 'comparison_operator', 'children': ['100', '101', '104'], 'value': '<='}; {'id': '100', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '101', 'type': 'subscript', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'header'}, {'id': '103', 'type': 'string', 'children': [], 'value': "'dump_type'"}; {'id': '104', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'raise_statement', 'children': ['107']}, {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'string', 'children': [], 'value': '"If you want to force to read as a scalar, you need to supply the quantities"'}, {'id': '111', 'type': 'else_clause', 'children': ['112']}; {'id': '112', 'type': 'block', 'children': ['113']}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '116', 'type': 'call', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'get_header'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'vprint'}, {'id': '123', 'type': 'conditional_expression', 'children': ['124', '127', '132'], 'value': 'if'}; {'id': '124', 'type': 'subscript', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '126', 'type': 'string', 'children': [], 'value': "'vprint'"}, {'id': '127', 'type': 'call', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'test'}, {'id': '129', 'type': 'argument_list', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'kw'}, {'id': '131', 'type': 'string', 'children': [], 'value': "'vprint'"}; {'id': '132', 'type': 'lambda', 'children': ['133', '135']}, {'id': '133', 'type': 'lambda_parameters', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '135', 'type': 'None', 'children': []}; {'id': '136', 'type': 'if_statement', 'children': ['137', '143']}, {'id': '137', 'type': 'comparison_operator', 'children': ['138', '139', '142'], 'value': '<='}; {'id': '138', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'header'}, {'id': '141', 'type': 'string', 'children': [], 'value': "'dump_type'"}; {'id': '142', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '143', 'type': 'block', 'children': ['144', '172', '180', '188', '207', '215']}; {'id': '144', 'type': 'if_statement', 'children': ['145', '151', '164']}, {'id': '145', 'type': 'not_operator', 'children': ['146']}; {'id': '146', 'type': 'call', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '148', 'type': 'argument_list', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '150', 'type': 'string', 'children': [], 'value': "'var'"}, {'id': '151', 'type': 'block', 'children': ['152']}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '155', 'type': 'list_comprehension', 'children': ['156', '159']}; {'id': '156', 'type': 'subscript', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '158', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '159', 'type': 'for_in_clause', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '161', 'type': 'subscript', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'header'}, {'id': '163', 'type': 'string', 'children': [], 'value': "'quantities'"}; {'id': '164', 'type': 'else_clause', 'children': ['165']}, {'id': '165', 'type': 'block', 'children': ['166']}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'assignment', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '169', 'type': 'subscript', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'kw'}, {'id': '171', 'type': 'string', 'children': [], 'value': "'var'"}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'keep_edges'}, {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'test'}, {'id': '177', 'type': 'argument_list', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'kw'}, {'id': '179', 'type': 'string', 'children': [], 'value': "'keep_edges'"}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}, {'id': '181', 'type': 'assignment', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'first_sort'}, {'id': '183', 'type': 'call', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'test'}, {'id': '185', 'type': 'argument_list', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'kw'}, {'id': '187', 'type': 'string', 'children': [], 'value': "'first_sort'"}; {'id': '188', 'type': 'if_statement', 'children': ['189', '194', '201']}, {'id': '189', 'type': 'call', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'test'}, {'id': '191', 'type': 'argument_list', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'kw'}, {'id': '193', 'type': 'string', 'children': [], 'value': "'sort'"}; {'id': '194', 'type': 'block', 'children': ['195']}, {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'assignment', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '198', 'type': 'subscript', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '200', 'type': 'string', 'children': [], 'value': "'sort'"}, {'id': '201', 'type': 'else_clause', 'children': ['202']}; {'id': '202', 'type': 'block', 'children': ['203']}, {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'assignment', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '206', 'type': 'None', 'children': []}, {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'assignment', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'keep_xs'}; {'id': '210', 'type': 'call', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '212', 'type': 'argument_list', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '214', 'type': 'string', 'children': [], 'value': "'keep_xs'"}, {'id': '215', 'type': 'expression_statement', 'children': ['216']}; {'id': '216', 'type': 'assignment', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'return_array'}; {'id': '218', 'type': 'call', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '220', 'type': 'argument_list', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '222', 'type': 'string', 'children': [], 'value': "'return_array'"}, {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'assignment', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'readers'}; {'id': '226', 'type': 'dictionary', 'children': ['227', '235', '260', '288', '296']}, {'id': '227', 'type': 'pair', 'children': ['228', '229']}; {'id': '228', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '229', 'type': 'lambda', 'children': ['230']}; {'id': '230', 'type': 'call', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'read_particles'}; {'id': '232', 'type': 'argument_list', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'header'}, {'id': '235', 'type': 'pair', 'children': ['236', '237']}; {'id': '236', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '237', 'type': 'lambda', 'children': ['238']}; {'id': '238', 'type': 'call', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'read_flds'}; {'id': '240', 'type': 'argument_list', 'children': ['241', '242', '243', '244', '245', '248', '251', '254', '257']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'header'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'vprint'}, {'id': '245', 'type': 'keyword_argument', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'keep_edges'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'keep_edges'}; {'id': '248', 'type': 'keyword_argument', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'first_sort'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'first_sort'}, {'id': '251', 'type': 'keyword_argument', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '254', 'type': 'keyword_argument', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'keep_xs'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'keep_xs'}, {'id': '257', 'type': 'keyword_argument', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'return_array'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'return_array'}; {'id': '260', 'type': 'pair', 'children': ['261', '262']}, {'id': '261', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '262', 'type': 'lambda', 'children': ['263']}, {'id': '263', 'type': 'call', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'read_flds'}, {'id': '265', 'type': 'argument_list', 'children': ['266', '267', '268', '269', '270', '273', '276', '279', '282', '285']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'file'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'vprint'}; {'id': '270', 'type': 'keyword_argument', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'keep_edges'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'keep_edges'}, {'id': '273', 'type': 'keyword_argument', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'first_sort'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'first_sort'}; {'id': '276', 'type': 'keyword_argument', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '279', 'type': 'keyword_argument', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'keep_xs'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'keep_xs'}; {'id': '282', 'type': 'keyword_argument', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'return_array'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'return_array'}, {'id': '285', 'type': 'keyword_argument', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'vector'}, {'id': '287', 'type': 'False', 'children': []}; {'id': '288', 'type': 'pair', 'children': ['289', '290']}, {'id': '289', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '290', 'type': 'lambda', 'children': ['291']}, {'id': '291', 'type': 'call', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'read_movie'}, {'id': '293', 'type': 'argument_list', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'file'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '296', 'type': 'pair', 'children': ['297', '298']}, {'id': '297', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '298', 'type': 'lambda', 'children': ['299']}, {'id': '299', 'type': 'call', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'read_pext'}, {'id': '301', 'type': 'argument_list', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'file'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '304', 'type': 'try_statement', 'children': ['305', '316']}, {'id': '305', 'type': 'block', 'children': ['306']}; {'id': '306', 'type': 'expression_statement', 'children': ['307']}, {'id': '307', 'type': 'assignment', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '309', 'type': 'call', 'children': ['310', '315']}; {'id': '310', 'type': 'subscript', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'readers'}; {'id': '312', 'type': 'subscript', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '314', 'type': 'string', 'children': [], 'value': "'dump_type'"}, {'id': '315', 'type': 'argument_list', 'children': []}; {'id': '316', 'type': 'except_clause', 'children': ['317', '318']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '318', 'type': 'block', 'children': ['319']}, {'id': '319', 'type': 'raise_statement', 'children': ['320']}; {'id': '320', 'type': 'call', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'}; {'id': '322', 'type': 'argument_list', 'children': ['323']}, {'id': '323', 'type': 'string', 'children': [], 'value': '"Other file types not implemented yet!"'}; {'id': '324', 'type': 'return_statement', 'children': ['325']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'd'} | def read(fname,**kw):
'''
Reads an lsp output file and returns a raw dump of data,
sectioned into quantities either as an dictionary or a typed numpy array.
Parameters:
-----------
fname -- filename of thing to read
Keyword Arguments:
------------------
vprint -- Verbose printer. Used in scripts
override -- (type, start) => A tuple of a dump type and a place to start
in the passed file, useful to attempting to read semicorrupted
files.
gzip -- Read as a gzip file.
flds/sclr Specific Arguments:
-----------------------------
var -- list of quantities to be read. For fields, this can consist
of strings that include vector components, e.g., 'Ex'. If
None (default), read all quantities.
keep_edges -- If set to truthy, then don't remove the edges from domains before
concatenation and don't reshape the flds data.
sort -- If not None, sort using these indices, useful for avoiding
resorting. If True and not an ndarray, just sort.
first_sort -- If truthy, sort, and return the sort data for future flds
that should have the same shape.
keep_xs -- Keep the xs's, that is, the grid information. Usually redundant
with x,y,z returned.
return_array -- If set to truthy, then try to return a numpy array with a dtype.
Requires of course that the quantities have the same shape.
'''
if test(kw,'gzip') and kw['gzip'] == 'guess':
kw['gzip'] = re.search(r'\.gz$', fname) is not None;
openf = gzip.open if test(kw, 'gzip') else open;
with openf(fname,'rb') as file:
if test(kw,'override'):
dump, start = kw['override'];
file.seek(start);
header = {'dump_type': dump};
if not test(kw, 'var') and 2 <= header['dump_type'] <= 3 :
raise ValueError(
"If you want to force to read as a scalar, you need to supply the quantities"
);
else:
header = get_header(file);
vprint = kw['vprint'] if test(kw, 'vprint') else lambda s: None;
if 2 <= header['dump_type'] <= 3 :
if not test(kw, 'var'):
var=[i[0] for i in header['quantities']];
else:
var=kw['var'];
keep_edges = test(kw, 'keep_edges');
first_sort = test(kw, 'first_sort');
if test(kw,'sort'):
sort = kw['sort']
else:
sort = None;
keep_xs = test(kw, 'keep_xs');
return_array = test(kw, 'return_array');
readers = {
1: lambda: read_particles(file, header),
2: lambda: read_flds(
file,header,var,vprint,
keep_edges=keep_edges,
first_sort=first_sort,
sort=sort,
keep_xs=keep_xs,
return_array=return_array),
3: lambda: read_flds(
file,header,var, vprint,
keep_edges=keep_edges,
first_sort=first_sort,
sort=sort,
keep_xs=keep_xs,
return_array=return_array,
vector=False),
6: lambda: read_movie(file, header),
10:lambda: read_pext(file,header)
};
try:
d = readers[header['dump_type']]();
except KeyError:
raise NotImplementedError("Other file types not implemented yet!");
return d; |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_region_nt_counts'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'region'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'bam'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'stranded'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '28', '182', '191', '218', '233', '468']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '17']}, {'id': '11', 'type': 'comparison_operator', 'children': ['12', '16'], 'value': '=='}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'bam'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'bam'}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'pysam'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'AlignmentFile'}, {'id': '25', 'type': 'argument_list', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'bam'}, {'id': '27', 'type': 'string', 'children': [], 'value': "'rb'"}; {'id': '28', 'type': 'if_statement', 'children': ['29', '35', '122']}, {'id': '29', 'type': 'comparison_operator', 'children': ['30', '34'], 'value': 'is'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'region'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '35', 'type': 'block', 'children': ['36', '43', '74', '81', '88', '108']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'parse_region'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'region'}, {'id': '43', 'type': 'if_statement', 'children': ['44', '50', '58']}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '49'], 'value': '=='}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '49', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '50', 'type': 'block', 'children': ['51']}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '57']}, {'id': '53', 'type': 'pattern_list', 'children': ['54', '55', '56']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'chrom'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '58', 'type': 'elif_clause', 'children': ['59', '65']}, {'id': '59', 'type': 'comparison_operator', 'children': ['60', '64'], 'value': '=='}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '64', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '73']}; {'id': '68', 'type': 'pattern_list', 'children': ['69', '70', '71', '72']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'chrom'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'strand'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'ind'}, {'id': '91', 'type': 'list_comprehension', 'children': ['92', '99']}; {'id': '92', 'type': 'call', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'string', 'children': [], 'value': "'{}:{}'"}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '96', 'type': 'argument_list', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'chrom'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '99', 'type': 'for_in_clause', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '103', 'type': 'argument_list', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '105', 'type': 'binary_operator', 'children': ['106', '107'], 'value': '+'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '107', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'pp'}, {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'bam'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'pileup'}, {'id': '115', 'type': 'argument_list', 'children': ['116', '119']}; {'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'region'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'region'}, {'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'truncate'}, {'id': '121', 'type': 'True', 'children': []}; {'id': '122', 'type': 'elif_clause', 'children': ['123', '132']}, {'id': '123', 'type': 'comparison_operator', 'children': ['124', '128'], 'value': 'is'}; {'id': '124', 'type': 'call', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'region'}; {'id': '128', 'type': 'parenthesized_expression', 'children': ['129'], 'value': '()'}, {'id': '129', 'type': 'boolean_operator', 'children': ['130', '131'], 'value': 'or'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '132', 'type': 'block', 'children': ['133', '140', '168']}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '139']}, {'id': '135', 'type': 'pattern_list', 'children': ['136', '137', '138']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'chrom'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'region'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'ind'}, {'id': '143', 'type': 'list_comprehension', 'children': ['144', '151']}; {'id': '144', 'type': 'call', 'children': ['145', '148']}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'string', 'children': [], 'value': "'{}:{}'"}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '148', 'type': 'argument_list', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'chrom'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '151', 'type': 'for_in_clause', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '155', 'type': 'argument_list', 'children': ['156', '162']}; {'id': '156', 'type': 'binary_operator', 'children': ['157', '161'], 'value': '+'}, {'id': '157', 'type': 'call', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '161', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '162', 'type': 'binary_operator', 'children': ['163', '167'], 'value': '+'}, {'id': '163', 'type': 'call', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '167', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'pp'}, {'id': '171', 'type': 'call', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'bam'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'pileup'}, {'id': '175', 'type': 'argument_list', 'children': ['176', '177', '178', '179']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'chrom'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '179', 'type': 'keyword_argument', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'truncate'}, {'id': '181', 'type': 'True', 'children': []}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'cols'}, {'id': '185', 'type': 'list', 'children': ['186', '187', '188', '189', '190'], 'value': "['A', 'T', 'C', 'G', 'N']"}; {'id': '186', 'type': 'string', 'children': [], 'value': "'A'"}, {'id': '187', 'type': 'string', 'children': [], 'value': "'T'"}; {'id': '188', 'type': 'string', 'children': [], 'value': "'C'"}, {'id': '189', 'type': 'string', 'children': [], 'value': "'G'"}; {'id': '190', 'type': 'string', 'children': [], 'value': "'N'"}, {'id': '191', 'type': 'if_statement', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'stranded'}, {'id': '193', 'type': 'block', 'children': ['194']}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'assignment', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'cols'}, {'id': '197', 'type': 'binary_operator', 'children': ['198', '208'], 'value': '+'}; {'id': '198', 'type': 'list_comprehension', 'children': ['199', '205']}, {'id': '199', 'type': 'call', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}, {'id': '201', 'type': 'string', 'children': [], 'value': "'{}+'"}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '205', 'type': 'for_in_clause', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '208', 'type': 'list_comprehension', 'children': ['209', '215']}, {'id': '209', 'type': 'call', 'children': ['210', '213']}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}, {'id': '211', 'type': 'string', 'children': [], 'value': "'{}-'"}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '215', 'type': 'for_in_clause', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}, {'id': '219', 'type': 'assignment', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'counts'}, {'id': '221', 'type': 'call', 'children': ['222', '225']}; {'id': '222', 'type': 'attribute', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'DataFrame'}, {'id': '225', 'type': 'argument_list', 'children': ['226', '227', '230']}; {'id': '226', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '227', 'type': 'keyword_argument', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'ind'}; {'id': '230', 'type': 'keyword_argument', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'cols'}, {'id': '233', 'type': 'for_statement', 'children': ['234', '235', '236']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'pc'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'pp'}; {'id': '236', 'type': 'block', 'children': ['237', '245', '249', '253', '257', '261', '323', '335', '347', '365', '384', '392', '396', '409', '422', '434', '447']}, {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'assignment', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '240', 'type': 'binary_operator', 'children': ['241', '244'], 'value': '+'}, {'id': '241', 'type': 'attribute', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'pc'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'reference_pos'}; {'id': '244', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'assignment', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'r1_qnames'}; {'id': '248', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '249', 'type': 'expression_statement', 'children': ['250']}; {'id': '250', 'type': 'assignment', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'r1_nts'}; {'id': '252', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'assignment', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'r2_qnames'}; {'id': '256', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '257', 'type': 'expression_statement', 'children': ['258']}; {'id': '258', 'type': 'assignment', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'r2_nts'}; {'id': '260', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '261', 'type': 'for_statement', 'children': ['262', '263', '266']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'pr'}, {'id': '263', 'type': 'attribute', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'pc'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'pileups'}; {'id': '266', 'type': 'block', 'children': ['267', '279', '291', '302']}, {'id': '267', 'type': 'expression_statement', 'children': ['268']}; {'id': '268', 'type': 'assignment', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'qnames'}; {'id': '270', 'type': 'subscript', 'children': ['271', '274']}, {'id': '271', 'type': 'list', 'children': ['272', '273'], 'value': '[r1_qnames, r2_qnames]'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'r1_qnames'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'r2_qnames'}; {'id': '274', 'type': 'attribute', 'children': ['275', '278']}, {'id': '275', 'type': 'attribute', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'pr'}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'alignment'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'is_read2'}, {'id': '279', 'type': 'expression_statement', 'children': ['280']}; {'id': '280', 'type': 'assignment', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'nts'}; {'id': '282', 'type': 'subscript', 'children': ['283', '286']}, {'id': '283', 'type': 'list', 'children': ['284', '285'], 'value': '[r1_nts, r2_nts]'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'r1_nts'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'r2_nts'}; {'id': '286', 'type': 'attribute', 'children': ['287', '290']}, {'id': '287', 'type': 'attribute', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'pr'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'alignment'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'is_read2'}, {'id': '291', 'type': 'expression_statement', 'children': ['292']}; {'id': '292', 'type': 'assignment', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'nt'}; {'id': '294', 'type': 'call', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': '_pos_nt'}; {'id': '296', 'type': 'argument_list', 'children': ['297', '298', '301']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'pr'}; {'id': '298', 'type': 'attribute', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'pc'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'reference_pos'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'stranded'}; {'id': '302', 'type': 'if_statement', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'nt'}; {'id': '304', 'type': 'block', 'children': ['305', '316']}, {'id': '305', 'type': 'expression_statement', 'children': ['306']}; {'id': '306', 'type': 'call', 'children': ['307', '310']}, {'id': '307', 'type': 'attribute', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'qnames'}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '310', 'type': 'argument_list', 'children': ['311']}, {'id': '311', 'type': 'attribute', 'children': ['312', '315']}; {'id': '312', 'type': 'attribute', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'pr'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'alignment'}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'qname'}; {'id': '316', 'type': 'expression_statement', 'children': ['317']}, {'id': '317', 'type': 'call', 'children': ['318', '321']}; {'id': '318', 'type': 'attribute', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'nts'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '321', 'type': 'argument_list', 'children': ['322']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'nt'}, {'id': '323', 'type': 'expression_statement', 'children': ['324']}; {'id': '324', 'type': 'assignment', 'children': ['325', '326']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'r1'}; {'id': '326', 'type': 'call', 'children': ['327', '330']}, {'id': '327', 'type': 'attribute', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'pd'}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'Series'}; {'id': '330', 'type': 'argument_list', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'r1_nts'}; {'id': '332', 'type': 'keyword_argument', 'children': ['333', '334']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'r1_qnames'}, {'id': '335', 'type': 'expression_statement', 'children': ['336']}; {'id': '336', 'type': 'assignment', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'r2'}; {'id': '338', 'type': 'call', 'children': ['339', '342']}, {'id': '339', 'type': 'attribute', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'pd'}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'Series'}; {'id': '342', 'type': 'argument_list', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'r2_nts'}; {'id': '344', 'type': 'keyword_argument', 'children': ['345', '346']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'r2_qnames'}, {'id': '347', 'type': 'expression_statement', 'children': ['348']}; {'id': '348', 'type': 'assignment', 'children': ['349', '350']}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '350', 'type': 'attribute', 'children': ['351', '364']}, {'id': '351', 'type': 'call', 'children': ['352', '355']}; {'id': '352', 'type': 'attribute', 'children': ['353', '354']}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'DataFrame'}, {'id': '355', 'type': 'argument_list', 'children': ['356', '359']}; {'id': '356', 'type': 'list', 'children': ['357', '358'], 'value': '[r1, r2]'}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'r1'}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'r2'}, {'id': '359', 'type': 'keyword_argument', 'children': ['360', '361']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '361', 'type': 'list', 'children': ['362', '363'], 'value': "['R1', 'R2']"}; {'id': '362', 'type': 'string', 'children': [], 'value': "'R1'"}, {'id': '363', 'type': 'string', 'children': [], 'value': "'R2'"}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'T'}, {'id': '365', 'type': 'expression_statement', 'children': ['366']}; {'id': '366', 'type': 'assignment', 'children': ['367', '368']}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'singles'}; {'id': '368', 'type': 'subscript', 'children': ['369', '370']}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '370', 'type': 'comparison_operator', 'children': ['371', '383'], 'value': '=='}, {'id': '371', 'type': 'call', 'children': ['372', '379']}; {'id': '372', 'type': 'attribute', 'children': ['373', '378']}, {'id': '373', 'type': 'call', 'children': ['374', '377']}; {'id': '374', 'type': 'attribute', 'children': ['375', '376']}, {'id': '375', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'isnull'}, {'id': '377', 'type': 'argument_list', 'children': []}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'sum'}, {'id': '379', 'type': 'argument_list', 'children': ['380']}; {'id': '380', 'type': 'keyword_argument', 'children': ['381', '382']}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '382', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '383', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '384', 'type': 'expression_statement', 'children': ['385']}, {'id': '385', 'type': 'assignment', 'children': ['386', '387']}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'doubles'}, {'id': '387', 'type': 'call', 'children': ['388', '391']}; {'id': '388', 'type': 'attribute', 'children': ['389', '390']}, {'id': '389', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'dropna'}, {'id': '391', 'type': 'argument_list', 'children': []}; {'id': '392', 'type': 'expression_statement', 'children': ['393']}, {'id': '393', 'type': 'assignment', 'children': ['394', '395']}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'vcs'}, {'id': '395', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '396', 'type': 'expression_statement', 'children': ['397']}, {'id': '397', 'type': 'call', 'children': ['398', '401']}; {'id': '398', 'type': 'attribute', 'children': ['399', '400']}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'vcs'}; {'id': '400', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '401', 'type': 'argument_list', 'children': ['402']}; {'id': '402', 'type': 'call', 'children': ['403', '408']}, {'id': '403', 'type': 'attribute', 'children': ['404', '407']}; {'id': '404', 'type': 'subscript', 'children': ['405', '406']}, {'id': '405', 'type': 'identifier', 'children': [], 'value': 'singles'}; {'id': '406', 'type': 'string', 'children': [], 'value': "'R1'"}, {'id': '407', 'type': 'identifier', 'children': [], 'value': 'value_counts'}; {'id': '408', 'type': 'argument_list', 'children': []}, {'id': '409', 'type': 'expression_statement', 'children': ['410']}; {'id': '410', 'type': 'call', 'children': ['411', '414']}, {'id': '411', 'type': 'attribute', 'children': ['412', '413']}; {'id': '412', 'type': 'identifier', 'children': [], 'value': 'vcs'}, {'id': '413', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '414', 'type': 'argument_list', 'children': ['415']}, {'id': '415', 'type': 'call', 'children': ['416', '421']}; {'id': '416', 'type': 'attribute', 'children': ['417', '420']}, {'id': '417', 'type': 'subscript', 'children': ['418', '419']}; {'id': '418', 'type': 'identifier', 'children': [], 'value': 'singles'}, {'id': '419', 'type': 'string', 'children': [], 'value': "'R2'"}; {'id': '420', 'type': 'identifier', 'children': [], 'value': 'value_counts'}, {'id': '421', 'type': 'argument_list', 'children': []}; {'id': '422', 'type': 'expression_statement', 'children': ['423']}, {'id': '423', 'type': 'assignment', 'children': ['424', '425']}; {'id': '424', 'type': 'identifier', 'children': [], 'value': 'doubles'}, {'id': '425', 'type': 'subscript', 'children': ['426', '427']}; {'id': '426', 'type': 'identifier', 'children': [], 'value': 'doubles'}, {'id': '427', 'type': 'comparison_operator', 'children': ['428', '431'], 'value': '=='}; {'id': '428', 'type': 'attribute', 'children': ['429', '430']}, {'id': '429', 'type': 'identifier', 'children': [], 'value': 'doubles'}; {'id': '430', 'type': 'identifier', 'children': [], 'value': 'R1'}, {'id': '431', 'type': 'attribute', 'children': ['432', '433']}; {'id': '432', 'type': 'identifier', 'children': [], 'value': 'doubles'}, {'id': '433', 'type': 'identifier', 'children': [], 'value': 'R2'}; {'id': '434', 'type': 'expression_statement', 'children': ['435']}, {'id': '435', 'type': 'call', 'children': ['436', '439']}; {'id': '436', 'type': 'attribute', 'children': ['437', '438']}, {'id': '437', 'type': 'identifier', 'children': [], 'value': 'vcs'}; {'id': '438', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '439', 'type': 'argument_list', 'children': ['440']}; {'id': '440', 'type': 'call', 'children': ['441', '446']}, {'id': '441', 'type': 'attribute', 'children': ['442', '445']}; {'id': '442', 'type': 'attribute', 'children': ['443', '444']}, {'id': '443', 'type': 'identifier', 'children': [], 'value': 'doubles'}; {'id': '444', 'type': 'identifier', 'children': [], 'value': 'R1'}, {'id': '445', 'type': 'identifier', 'children': [], 'value': 'value_counts'}; {'id': '446', 'type': 'argument_list', 'children': []}, {'id': '447', 'type': 'for_statement', 'children': ['448', '449', '450']}; {'id': '448', 'type': 'identifier', 'children': [], 'value': 'vc'}, {'id': '449', 'type': 'identifier', 'children': [], 'value': 'vcs'}; {'id': '450', 'type': 'block', 'children': ['451']}, {'id': '451', 'type': 'expression_statement', 'children': ['452']}; {'id': '452', 'type': 'augmented_assignment', 'children': ['453', '467'], 'value': '+='}, {'id': '453', 'type': 'subscript', 'children': ['454', '457', '464']}; {'id': '454', 'type': 'attribute', 'children': ['455', '456']}, {'id': '455', 'type': 'identifier', 'children': [], 'value': 'counts'}; {'id': '456', 'type': 'identifier', 'children': [], 'value': 'ix'}, {'id': '457', 'type': 'call', 'children': ['458', '461']}; {'id': '458', 'type': 'attribute', 'children': ['459', '460']}, {'id': '459', 'type': 'string', 'children': [], 'value': "'{}:{}'"}; {'id': '460', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '461', 'type': 'argument_list', 'children': ['462', '463']}; {'id': '462', 'type': 'identifier', 'children': [], 'value': 'chrom'}, {'id': '463', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '464', 'type': 'attribute', 'children': ['465', '466']}, {'id': '465', 'type': 'identifier', 'children': [], 'value': 'vc'}; {'id': '466', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '467', 'type': 'identifier', 'children': [], 'value': 'vc'}; {'id': '468', 'type': 'return_statement', 'children': ['469']}, {'id': '469', 'type': 'identifier', 'children': [], 'value': 'counts'} | def get_region_nt_counts(region, bam, stranded=False):
if type(bam) == str:
bam = pysam.AlignmentFile(bam, 'rb')
if type(region) is str:
r = parse_region(region)
if len(r) == 3:
chrom, start, end = r
elif len(r) == 4:
chrom, start, end, strand = r
start = int(start)
end = int(end)
ind = ['{}:{}'.format(chrom, x) for
x in range(start, end + 1)]
pp = bam.pileup(region=region, truncate=True)
elif type(region) is (list or tuple):
chrom, start, end = region
ind = ['{}:{}'.format(chrom, x) for
x in range(int(start) + 1, int(end) + 1)]
pp = bam.pileup(chrom, start, end, truncate=True)
cols = ['A', 'T', 'C', 'G', 'N']
if stranded:
cols = ['{}+'.format(x) for x in cols] + ['{}-'.format(x) for x in cols]
counts = pd.DataFrame(0, index=ind, columns=cols)
for pc in pp:
pos = pc.reference_pos + 1
r1_qnames = []
r1_nts = []
r2_qnames = []
r2_nts = []
for pr in pc.pileups:
qnames = [r1_qnames, r2_qnames][pr.alignment.is_read2]
nts = [r1_nts, r2_nts][pr.alignment.is_read2]
nt = _pos_nt(pr, pc.reference_pos, stranded)
if nt:
qnames.append(pr.alignment.qname)
nts.append(nt)
r1 = pd.Series(r1_nts, index=r1_qnames)
r2 = pd.Series(r2_nts, index=r2_qnames)
df = pd.DataFrame([r1, r2], index=['R1', 'R2']).T
singles = df[df.isnull().sum(axis=1) == 1]
doubles = df.dropna()
vcs = []
vcs.append(singles['R1'].value_counts())
vcs.append(singles['R2'].value_counts())
doubles = doubles[doubles.R1 == doubles.R2]
vcs.append(doubles.R1.value_counts())
for vc in vcs:
counts.ix['{}:{}'.format(chrom, pos), vc.index] += vc
return counts |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'nt_counts'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'bam'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'positions'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'stranded'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'vcf'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'bed'}; {'id': '14', 'type': 'False', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16', '84', '154', '158', '198', '207']}; {'id': '16', 'type': 'if_statement', 'children': ['17', '22']}, {'id': '17', 'type': 'boolean_operator', 'children': ['18', '20'], 'value': 'and'}; {'id': '18', 'type': 'not_operator', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'bed'}; {'id': '20', 'type': 'not_operator', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'vcf'}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'if_statement', 'children': ['24', '34', '43', '57', '71']}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '29'], 'value': '=='}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'positions'}, {'id': '29', 'type': 'attribute', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'pbt'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'bedtool'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'BedTool'}; {'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': 'df'}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'positions'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'to_dataframe'}; {'id': '42', 'type': 'argument_list', 'children': []}, {'id': '43', 'type': 'elif_clause', 'children': ['44', '52']}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '51'], 'value': '=='}, {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'positions'}, {'id': '47', 'type': 'slice', 'children': ['48', '50']}; {'id': '48', 'type': 'unary_operator', 'children': ['49'], 'value': '-'}, {'id': '49', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '50', 'type': 'colon', 'children': []}, {'id': '51', 'type': 'string', 'children': [], 'value': "'.bed'"}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'bed'}; {'id': '56', 'type': 'True', 'children': []}, {'id': '57', 'type': 'elif_clause', 'children': ['58', '66']}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '65'], 'value': '=='}, {'id': '59', 'type': 'subscript', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'positions'}, {'id': '61', 'type': 'slice', 'children': ['62', '64']}; {'id': '62', 'type': 'unary_operator', 'children': ['63'], 'value': '-'}, {'id': '63', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '64', 'type': 'colon', 'children': []}, {'id': '65', 'type': 'string', 'children': [], 'value': "'.vcf'"}; {'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': 'vcf'}; {'id': '70', 'type': 'True', 'children': []}, {'id': '71', 'type': 'else_clause', 'children': ['72']}; {'id': '72', 'type': 'block', 'children': ['73']}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '80']}, {'id': '75', 'type': 'attribute', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'stderr'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'concatenated_string', 'children': ['82', '83']}; {'id': '82', 'type': 'string', 'children': [], 'value': "'Positions must be BedTool, bed file, or vcf '"}, {'id': '83', 'type': 'string', 'children': [], 'value': "'file.\\n'"}; {'id': '84', 'type': 'if_statement', 'children': ['85', '86', '100']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'bed'}; {'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': 'df'}; {'id': '90', 'type': 'call', 'children': ['91', '99']}, {'id': '91', 'type': 'attribute', 'children': ['92', '98']}; {'id': '92', 'type': 'call', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'pbt'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'BedTool'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'positions'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'to_dataframe'}, {'id': '99', 'type': 'argument_list', 'children': []}; {'id': '100', 'type': 'elif_clause', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'vcf'}; {'id': '102', 'type': 'block', 'children': ['103', '108', '115', '128', '136', '146']}, {'id': '103', 'type': 'import_from_statement', 'children': ['104', '106']}; {'id': '104', 'type': 'dotted_name', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'variants'}; {'id': '106', 'type': 'dotted_name', 'children': ['107']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'vcf_as_df'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'tdf'}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'vcf_as_df'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'positions'}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '118', 'type': 'call', 'children': ['119', '122']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'pd'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'DataFrame'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}, {'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'tdf'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'assignment', 'children': ['130', '133']}; {'id': '130', 'type': 'subscript', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '132', 'type': 'string', 'children': [], 'value': "'chrom'"}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'tdf'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'CHROM'}; {'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': 'df'}; {'id': '140', 'type': 'string', 'children': [], 'value': "'start'"}, {'id': '141', 'type': 'binary_operator', 'children': ['142', '145'], 'value': '-'}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'tdf'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'POS'}, {'id': '145', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'assignment', 'children': ['148', '151']}; {'id': '148', 'type': 'subscript', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '150', 'type': 'string', 'children': [], 'value': "'end'"}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'tdf'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'POS'}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '157', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '158', 'type': 'for_statement', 'children': ['159', '160', '163']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '163', 'type': 'block', 'children': ['164', '186']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'assignment', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'region'}, {'id': '167', 'type': 'list', 'children': ['168', '174', '180'], 'value': "[df.ix[i, 'chrom'], df.ix[i, 'start'], df.ix[i, 'end']]"}; {'id': '168', 'type': 'subscript', 'children': ['169', '172', '173']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'ix'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '173', 'type': 'string', 'children': [], 'value': "'chrom'"}; {'id': '174', 'type': 'subscript', 'children': ['175', '178', '179']}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'ix'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '179', 'type': 'string', 'children': [], 'value': "'start'"}; {'id': '180', 'type': 'subscript', 'children': ['181', '184', '185']}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'ix'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '185', 'type': 'string', 'children': [], 'value': "'end'"}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}, {'id': '187', 'type': 'call', 'children': ['188', '191']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'call', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'get_region_nt_counts'}; {'id': '194', 'type': 'argument_list', 'children': ['195', '196', '197']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'region'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'bam'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'stranded'}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}, {'id': '199', 'type': 'assignment', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '201', 'type': 'call', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'concat'}, {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '207', 'type': 'return_statement', 'children': ['208']} | def nt_counts(bam, positions, stranded=False, vcf=False, bed=False):
if not bed and not vcf:
if type(positions) == pbt.bedtool.BedTool:
df = positions.to_dataframe()
elif positions[-4:] == '.bed':
bed = True
elif positions[-4:] == '.vcf':
vcf = True
else:
sys.stderr.write('Positions must be BedTool, bed file, or vcf '
'file.\n')
if bed:
df = pbt.BedTool(positions).to_dataframe()
elif vcf:
from variants import vcf_as_df
tdf = vcf_as_df(positions)
df = pd.DataFrame(index=tdf.index)
df['chrom'] = tdf.CHROM
df['start'] = tdf.POS - 1
df['end'] = tdf.POS
res = []
for i in df.index:
region = [df.ix[i, 'chrom'], df.ix[i, 'start'], df.ix[i, 'end']]
res.append(get_region_nt_counts(region, bam, stranded))
res = pd.concat(res)
return res |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_host'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'group_names'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'host_vars'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '20', '27', '33', '43', '53', '70', '80']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'gnames'}; {'id': '16', 'type': 'conditional_expression', 'children': ['17', '18', '19'], 'value': 'if'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'group_names'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'group_names'}, {'id': '19', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'hvars'}, {'id': '23', 'type': 'conditional_expression', 'children': ['24', '25', '26'], 'value': 'if'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'host_vars'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'host_vars'}; {'id': '26', 'type': 'dictionary', 'children': []}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'gnames'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '32', 'type': 'argument_list', 'children': []}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '42']}, {'id': '35', 'type': 'subscript', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'hvars'}, {'id': '37', 'type': 'attribute', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'server'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'GROUP_NAMES'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'gnames'}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '52']}, {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'hvars'}, {'id': '47', 'type': 'attribute', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'server'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'INV_NAME'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'host'}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '62']}, {'id': '55', 'type': 'subscript', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'hvars'}, {'id': '57', 'type': 'attribute', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'server'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'INV_NAME_SHORT'}; {'id': '62', 'type': 'subscript', 'children': ['63', '69']}, {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '69', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '77']}; {'id': '72', 'type': 'attribute', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'groups_and_vars'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'merge'}, {'id': '77', 'type': 'argument_list', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'host'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'hvars'}; {'id': '80', 'type': 'for_statement', 'children': ['81', '82', '83']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'gname'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'group_names'}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'call', 'children': ['86', '91']}; {'id': '86', 'type': 'attribute', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'groups_and_vars'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '91', 'type': 'argument_list', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'gname'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'host'} | def add_host(self, host, group_names=None, host_vars=None):
gnames = group_names if group_names else []
hvars = host_vars if host_vars else {}
gnames.sort()
hvars[A.server.GROUP_NAMES] = gnames
hvars[A.server.INV_NAME] = host
hvars[A.server.INV_NAME_SHORT] = host.split('.')[0]
self.groups_and_vars.merge(host, hvars)
for gname in group_names:
self.groups_and_vars.append(gname, host) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'beds_to_boolean'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'beds'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'ref'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'beds_sorted'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'ref_sorted'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'dictionary_splat_pattern', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '16', 'type': 'block', 'children': ['17', '26', '30', '92', '100', '141', '145', '169', '184', '247']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'beds'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'deepcopy'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'beds'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'fns'}, {'id': '29', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '30', 'type': 'for_statement', 'children': ['31', '34', '38']}, {'id': '31', 'type': 'pattern_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'beds'}; {'id': '38', 'type': 'block', 'children': ['39', '76']}, {'id': '39', 'type': 'if_statement', 'children': ['40', '46', '65']}; {'id': '40', 'type': 'comparison_operator', 'children': ['41', '45'], 'value': '=='}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '46', 'type': 'block', 'children': ['47', '54']}, {'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': 'fns'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '59']}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'beds'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'pbt'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'BedTool'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '65', 'type': 'else_clause', 'children': ['66']}; {'id': '66', 'type': 'block', 'children': ['67']}, {'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': 'fns'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '76', 'type': 'if_statement', 'children': ['77', '79']}, {'id': '77', 'type': 'not_operator', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'beds_sorted'}, {'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': 'beds'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '85', 'type': 'call', 'children': ['86', '91']}; {'id': '86', 'type': 'attribute', 'children': ['87', '90']}, {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'beds'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '91', 'type': 'argument_list', 'children': []}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'names'}, {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': '_sample_names'}, {'id': '97', 'type': 'argument_list', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'fns'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '100', 'type': 'if_statement', 'children': ['101', '102', '132']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '102', 'type': 'block', 'children': ['103', '120']}, {'id': '103', 'type': 'if_statement', 'children': ['104', '110']}; {'id': '104', 'type': 'comparison_operator', 'children': ['105', '109'], 'value': '=='}, {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'ref'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '110', 'type': 'block', 'children': ['111']}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '114', 'type': 'call', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'pbt'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'BedTool'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '120', 'type': 'if_statement', 'children': ['121', '123']}, {'id': '121', 'type': 'not_operator', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'ref_sorted'}, {'id': '123', 'type': 'block', 'children': ['124']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'ref'}, {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '131', 'type': 'argument_list', 'children': []}; {'id': '132', 'type': 'else_clause', 'children': ['133']}, {'id': '133', 'type': 'block', 'children': ['134']}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'ref'}, {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'combine'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'beds'}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'ind'}; {'id': '144', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '145', 'type': 'for_statement', 'children': ['146', '147', '148']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '148', 'type': 'block', 'children': ['149']}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'call', 'children': ['151', '154']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'ind'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}, {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'string', 'children': [], 'value': "'{}:{}-{}'"}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '159', 'type': 'argument_list', 'children': ['160', '163', '166']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'chrom'}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'bdf'}; {'id': '172', 'type': 'call', 'children': ['173', '176']}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'pd'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'DataFrame'}; {'id': '176', 'type': 'argument_list', 'children': ['177', '178', '181']}, {'id': '177', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '178', 'type': 'keyword_argument', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'ind'}, {'id': '181', 'type': 'keyword_argument', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '184', 'type': 'for_statement', 'children': ['185', '188', '192']}, {'id': '185', 'type': 'pattern_list', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'bed'}; {'id': '188', 'type': 'call', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'beds'}; {'id': '192', 'type': 'block', 'children': ['193', '208', '212', '236']}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '196', 'type': 'call', 'children': ['197', '200']}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'ref'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'intersect'}; {'id': '200', 'type': 'argument_list', 'children': ['201', '202', '205']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'bed'}; {'id': '202', 'type': 'keyword_argument', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '204', 'type': 'True', 'children': []}, {'id': '205', 'type': 'keyword_argument', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'wa'}, {'id': '207', 'type': 'True', 'children': []}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}, {'id': '209', 'type': 'assignment', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'ind'}, {'id': '211', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '212', 'type': 'for_statement', 'children': ['213', '214', '215']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '215', 'type': 'block', 'children': ['216']}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}, {'id': '217', 'type': 'call', 'children': ['218', '221']}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'ind'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'call', 'children': ['223', '226']}, {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'string', 'children': [], 'value': "'{}:{}-{}'"}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '226', 'type': 'argument_list', 'children': ['227', '230', '233']}, {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'chrom'}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}, {'id': '237', 'type': 'assignment', 'children': ['238', '246']}; {'id': '238', 'type': 'subscript', 'children': ['239', '242', '243']}, {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'bdf'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'ix'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'ind'}, {'id': '243', 'type': 'subscript', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'names'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '246', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '247', 'type': 'return_statement', 'children': ['248']} | def beds_to_boolean(beds, ref=None, beds_sorted=False, ref_sorted=False,
**kwargs):
beds = copy.deepcopy(beds)
fns = []
for i,v in enumerate(beds):
if type(v) == str:
fns.append(v)
beds[i] = pbt.BedTool(v)
else:
fns.append(v.fn)
if not beds_sorted:
beds[i] = beds[i].sort()
names = _sample_names(fns, kwargs)
if ref:
if type(ref) == str:
ref = pbt.BedTool(ref)
if not ref_sorted:
ref = ref.sort()
else:
ref = combine(beds)
ind = []
for r in ref:
ind.append('{}:{}-{}'.format(r.chrom, r.start, r.stop))
bdf = pd.DataFrame(0, index=ind, columns=names)
for i,bed in enumerate(beds):
res = ref.intersect(bed, sorted=True, wa=True)
ind = []
for r in res:
ind.append('{}:{}-{}'.format(r.chrom,
r.start,
r.stop))
bdf.ix[ind, names[i]] = 1
return bdf |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'combine'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'beds'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'beds_sorted'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'postmerge'}; {'id': '10', 'type': 'True', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '21', '65', '85', '93', '104']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'beds'}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'deepcopy'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'beds'}, {'id': '21', 'type': 'for_statement', 'children': ['22', '25', '29']}; {'id': '22', 'type': 'pattern_list', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'beds'}, {'id': '29', 'type': 'block', 'children': ['30', '49']}; {'id': '30', 'type': 'if_statement', 'children': ['31', '37']}, {'id': '31', 'type': 'comparison_operator', 'children': ['32', '36'], 'value': '=='}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '43']}; {'id': '40', 'type': 'subscript', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'beds'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'pbt'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'BedTool'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '49', 'type': 'if_statement', 'children': ['50', '52']}; {'id': '50', 'type': 'not_operator', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'beds_sorted'}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '58']}, {'id': '55', 'type': 'subscript', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'beds'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '58', 'type': 'call', 'children': ['59', '64']}, {'id': '59', 'type': 'attribute', 'children': ['60', '63']}; {'id': '60', 'type': 'subscript', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'beds'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '64', 'type': 'argument_list', 'children': []}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'reduce'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '84']}, {'id': '71', 'type': 'lambda', 'children': ['72', '75']}; {'id': '72', 'type': 'lambda_parameters', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'cat'}, {'id': '79', 'type': 'argument_list', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'postmerge'}, {'id': '83', 'type': 'False', 'children': []}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'beds'}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '92', 'type': 'argument_list', 'children': []}, {'id': '93', 'type': 'if_statement', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'postmerge'}, {'id': '95', 'type': 'block', 'children': ['96']}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'merge'}, {'id': '103', 'type': 'argument_list', 'children': []}; {'id': '104', 'type': 'return_statement', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'out'} | def combine(beds, beds_sorted=False, postmerge=True):
beds = copy.deepcopy(beds)
for i,v in enumerate(beds):
if type(v) == str:
beds[i] = pbt.BedTool(v)
if not beds_sorted:
beds[i] = beds[i].sort()
out = reduce(lambda x,y : x.cat(y, postmerge=False), beds)
out = out.sort()
if postmerge:
out = out.merge()
return out |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sanitize_config_loglevel'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'level'}, {'id': '5', 'type': 'block', 'children': ['6', '8', '31', '35', '53', '64']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'string', 'children': [], 'value': "'''\n Kinda sorta backport of loglevel sanitization for Python 2.6.\n '''"}; {'id': '8', 'type': 'if_statement', 'children': ['9', '28']}, {'id': '9', 'type': 'boolean_operator', 'children': ['10', '21'], 'value': 'or'}; {'id': '10', 'type': 'comparison_operator', 'children': ['11', '18'], 'value': '!='}, {'id': '11', 'type': 'subscript', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'version_info'}, {'id': '15', 'type': 'slice', 'children': ['16', '17']}; {'id': '16', 'type': 'colon', 'children': []}, {'id': '17', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '18', 'type': 'tuple', 'children': ['19', '20']}, {'id': '19', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '20', 'type': 'integer', 'children': [], 'value': '6'}, {'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': 'level'}, {'id': '25', 'type': 'tuple', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'long'}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'return_statement', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'level'}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'lvl'}; {'id': '34', 'type': 'None', 'children': []}, {'id': '35', 'type': 'if_statement', 'children': ['36', '41']}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'basestring'}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'lvl'}, {'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': 'logging'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': '_levelNames'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'level'}, {'id': '53', 'type': 'if_statement', 'children': ['54', '56']}; {'id': '54', 'type': 'not_operator', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'lvl'}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'raise_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'binary_operator', 'children': ['62', '63'], 'value': '%'}; {'id': '62', 'type': 'string', 'children': [], 'value': "'Invalid log level, %s'"}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '64', 'type': 'return_statement', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'lvl'} | def sanitize_config_loglevel(level):
'''
Kinda sorta backport of loglevel sanitization for Python 2.6.
'''
if sys.version_info[:2] != (2, 6) or isinstance(level, (int, long)):
return level
lvl = None
if isinstance(level, basestring):
lvl = logging._levelNames.get(level)
if not lvl:
raise ValueError('Invalid log level, %s' % level)
return lvl |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'prt_js'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'js'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort_keys'}, {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'indent'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'js2str'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20', '21']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'js'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'sort_keys'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'indent'} | def prt_js(js, sort_keys=True, indent=4):
print(js2str(js, sort_keys, indent)) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_field_names'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_MODEL'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_APP'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'score_cutoff'}, {'id': '13', 'type': 'integer', 'children': [], 'value': '50'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'pad_with_none'}; {'id': '16', 'type': 'False', 'children': []}, {'id': '17', 'type': 'block', 'children': ['18', '27', '35', '45', '49', '96']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'util'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'listify'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'get_model'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'available_field_names'}; {'id': '38', 'type': 'call', 'children': ['39', '44']}, {'id': '39', 'type': 'attribute', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': '_meta'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'get_all_field_names'}; {'id': '44', 'type': 'argument_list', 'children': []}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'matched_fields'}; {'id': '48', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '49', 'type': 'for_statement', 'children': ['50', '51', '52']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'field_name'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '52', 'type': 'block', 'children': ['53', '66']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '56', 'type': 'call', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'fuzzy'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'extractOne'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '65']}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'field_name'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'available_field_names'}; {'id': '66', 'type': 'if_statement', 'children': ['67', '80', '88']}, {'id': '67', 'type': 'boolean_operator', 'children': ['68', '75'], 'value': 'and'}; {'id': '68', 'type': 'boolean_operator', 'children': ['69', '70'], 'value': 'and'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '74'], 'value': 'is'}, {'id': '71', 'type': 'subscript', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '73', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '74', 'type': 'None', 'children': []}, {'id': '75', 'type': 'comparison_operator', 'children': ['76', '79'], 'value': '>='}; {'id': '76', 'type': 'subscript', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '78', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'score_cutoff'}; {'id': '80', 'type': 'block', 'children': ['81']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'augmented_assignment', 'children': ['83', '84'], 'value': '+='}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'matched_fields'}; {'id': '84', 'type': 'list', 'children': ['85'], 'value': '[match[0]]'}, {'id': '85', 'type': 'subscript', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '87', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '88', 'type': 'elif_clause', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'pad_with_none'}; {'id': '90', 'type': 'block', 'children': ['91']}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'augmented_assignment', 'children': ['93', '94'], 'value': '+='}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'matched_fields'}; {'id': '94', 'type': 'list', 'children': ['95'], 'value': '[None]'}, {'id': '95', 'type': 'None', 'children': []}; {'id': '96', 'type': 'return_statement', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'matched_fields'} | def find_field_names(fields, model=DEFAULT_MODEL, app=DEFAULT_APP, score_cutoff=50, pad_with_none=False):
fields = util.listify(fields)
model = get_model(model, app)
available_field_names = model._meta.get_all_field_names()
matched_fields = []
for field_name in fields:
match = fuzzy.extractOne(str(field_name), available_field_names)
if match and match[1] is not None and match[1] >= score_cutoff:
matched_fields += [match[0]]
elif pad_with_none:
matched_fields += [None]
return matched_fields |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '34']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'lagged_in_date'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13', '16', '19', '22', '25', '28', '31']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '6', 'type': 'None', 'children': []}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'filter_dict'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '15', 'type': 'string', 'children': [], 'value': "'WikiItem'"}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_APP'}, {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '21', 'type': 'True', 'children': []}; {'id': '22', 'type': 'default_parameter', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '30000'}, {'id': '25', 'type': 'default_parameter', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'lag'}, {'id': '27', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '28', 'type': 'default_parameter', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'pad'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '31', 'type': 'default_parameter', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'truncate'}, {'id': '33', 'type': 'True', 'children': []}; {'id': '34', 'type': 'block', 'children': ['35', '44', '87', '161', '235']}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'lag'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'boolean_operator', 'children': ['42', '43'], 'value': 'or'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'lag'}, {'id': '43', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '44', 'type': 'if_statement', 'children': ['45', '56']}, {'id': '45', 'type': 'boolean_operator', 'children': ['46', '51'], 'value': 'and'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'basestring'}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'basestring'}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '62']}, {'id': '59', 'type': 'pattern_list', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'sequence_from_filter_spec'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '74', '75', '78', '81', '84']}, {'id': '65', 'type': 'list', 'children': ['66', '70'], 'value': '[find_synonymous_field(x), find_synonymous_field(y)]'}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'find_synonymous_field'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'find_synonymous_field'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'filter_dict'}, {'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '87', 'type': 'if_statement', 'children': ['88', '99']}; {'id': '88', 'type': 'boolean_operator', 'children': ['89', '90'], 'value': 'and'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '90', 'type': 'comparison_operator', 'children': ['91', '95'], 'value': '=='}, {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '99', 'type': 'block', 'children': ['100', '145']}; {'id': '100', 'type': 'if_statement', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '102', 'type': 'block', 'children': ['103', '125']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'xy'}; {'id': '106', 'type': 'call', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '108', 'type': 'argument_list', 'children': ['109', '114']}, {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'zip'}, {'id': '111', 'type': 'argument_list', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '116', 'type': 'call', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}, {'id': '119', 'type': 'comparison_operator', 'children': ['120', '124'], 'value': '<'}; {'id': '120', 'type': 'call', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '124', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '130']}, {'id': '127', 'type': 'pattern_list', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '130', 'type': 'expression_list', 'children': ['131', '138']}, {'id': '131', 'type': 'list_comprehension', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'col1'}, {'id': '133', 'type': 'for_in_clause', 'children': ['134', '137']}; {'id': '134', 'type': 'pattern_list', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'col1'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'col2'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'xy'}; {'id': '138', 'type': 'list_comprehension', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'col2'}; {'id': '140', 'type': 'for_in_clause', 'children': ['141', '144']}, {'id': '141', 'type': 'pattern_list', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'col1'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'col2'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'xy'}, {'id': '145', 'type': 'return_statement', 'children': ['146']}; {'id': '146', 'type': 'expression_list', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '148', 'type': 'call', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'lagged_seq'}; {'id': '150', 'type': 'argument_list', 'children': ['151', '152', '155', '158']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'lag'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'lag'}, {'id': '155', 'type': 'keyword_argument', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'pad'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'pad'}; {'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'truncate'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'truncate'}, {'id': '161', 'type': 'if_statement', 'children': ['162', '181']}; {'id': '162', 'type': 'boolean_operator', 'children': ['163', '169'], 'value': 'and'}, {'id': '163', 'type': 'boolean_operator', 'children': ['164', '165'], 'value': 'and'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '165', 'type': 'call', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '169', 'type': 'comparison_operator', 'children': ['170', '171', '175'], 'value': '=='}; {'id': '170', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'subscript', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '180', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '181', 'type': 'block', 'children': ['182', '206']}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'assignment', 'children': ['184', '187']}; {'id': '184', 'type': 'pattern_list', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '187', 'type': 'expression_list', 'children': ['188', '191']}; {'id': '188', 'type': 'subscript', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '190', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '191', 'type': 'call', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'lagged_seq'}, {'id': '193', 'type': 'argument_list', 'children': ['194', '197', '200', '203']}; {'id': '194', 'type': 'subscript', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '196', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '197', 'type': 'keyword_argument', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'lag'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'lag'}; {'id': '200', 'type': 'keyword_argument', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'pad'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'pad'}, {'id': '203', 'type': 'keyword_argument', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'truncate'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'truncate'}; {'id': '206', 'type': 'if_statement', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'truncate'}; {'id': '208', 'type': 'block', 'children': ['209', '212']}, {'id': '209', 'type': 'print_statement', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'truncate'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'lag'}; {'id': '212', 'type': 'if_statement', 'children': ['213', '216', '225']}, {'id': '213', 'type': 'comparison_operator', 'children': ['214', '215'], 'value': '>='}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'lag'}, {'id': '215', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '216', 'type': 'block', 'children': ['217']}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '220', 'type': 'subscript', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '222', 'type': 'slice', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'lag'}; {'id': '224', 'type': 'colon', 'children': []}, {'id': '225', 'type': 'else_clause', 'children': ['226']}; {'id': '226', 'type': 'block', 'children': ['227']}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '230', 'type': 'subscript', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '232', 'type': 'slice', 'children': ['233', '234']}, {'id': '233', 'type': 'colon', 'children': []}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'lag'}, {'id': '235', 'type': 'return_statement', 'children': ['236']}; {'id': '236', 'type': 'expression_list', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'x'} | def lagged_in_date(x=None, y=None, filter_dict=None, model='WikiItem', app=DEFAULT_APP, sort=True, limit=30000, lag=1, pad=0, truncate=True):
lag = int(lag or 0)
if isinstance(x, basestring) and isinstance(y, basestring):
x, y = sequence_from_filter_spec([find_synonymous_field(x), find_synonymous_field(y)], filter_dict, model=model,
app=app, sort=sort, limit=limit)
if y and len(y) == len(x):
if sort:
xy = sorted(zip(x,y), reverse=bool(int(sort) < 0))
x, y = [col1 for col1, col2 in xy], [col2 for col1, col2 in xy]
return x, lagged_seq(y, lag=lag, pad=pad, truncate=truncate)
if x and len(x) and 2 == len(x) <= len(x[0]):
x, y = x[0], lagged_seq(x[1], lag=lag, pad=pad, truncate=truncate)
if truncate:
print truncate, lag
if lag >= 0:
x = x[lag:]
else:
x = x[:lag]
return x, y |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'percentile'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'sorted_list'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'percent'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '8', 'type': 'lambda', 'children': ['9', '11']}, {'id': '9', 'type': 'lambda_parameters', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '12', 'type': 'block', 'children': ['13', '19', '32', '44', '51', '57', '85']}, {'id': '13', 'type': 'if_statement', 'children': ['14', '16']}; {'id': '14', 'type': 'not_operator', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'sorted_list'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'return_statement', 'children': ['18']}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'if_statement', 'children': ['20', '23']}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': '=='}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'percent'}; {'id': '22', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'return_statement', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'subscript', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'sorted_list'}; {'id': '30', 'type': 'unary_operator', 'children': ['31'], 'value': '-'}, {'id': '31', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '32', 'type': 'if_statement', 'children': ['33', '36']}, {'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': '=='}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'percent'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'return_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'subscript', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'sorted_list'}, {'id': '43', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'sorted_list'}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '54', 'type': 'binary_operator', 'children': ['55', '56'], 'value': '*'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'percent'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '57', 'type': 'if_statement', 'children': ['58', '64']}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '63'], 'value': '=='}, {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'ceil'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '64', 'type': 'block', 'children': ['65', '72']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '72', 'type': 'return_statement', 'children': ['73']}, {'id': '73', 'type': 'binary_operator', 'children': ['74', '84'], 'value': '/'}; {'id': '74', 'type': 'parenthesized_expression', 'children': ['75'], 'value': '()'}, {'id': '75', 'type': 'binary_operator', 'children': ['76', '81'], 'value': '+'}; {'id': '76', 'type': 'subscript', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'sorted_list'}; {'id': '78', 'type': 'binary_operator', 'children': ['79', '80'], 'value': '-'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '80', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '81', 'type': 'subscript', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'sorted_list'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '84', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '85', 'type': 'return_statement', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'subscript', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'sorted_list'}, {'id': '91', 'type': 'binary_operator', 'children': ['92', '96'], 'value': '-'}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'ceil'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'i'} | def percentile(sorted_list, percent, key=lambda x: x):
if not sorted_list:
return None
if percent == 1:
return float(sorted_list[-1])
if percent == 0:
return float(sorted_list[0])
n = len(sorted_list)
i = percent * n
if ceil(i) == i:
i = int(i)
return (sorted_list[i-1] + sorted_list[i]) / 2
return float(sorted_list[ceil(i)-1]) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'tags'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '8', '21', '30', '43', '56', '64']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'string', 'children': [], 'value': "'''Return a list of all tags that have this semantic tag, sorted by name.\n\t\t:rtype: list of ckan.model.tag.Tag objects\n\t\t'''"}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'q'}, {'id': '11', 'type': 'call', 'children': ['12', '17']}; {'id': '12', 'type': 'attribute', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'meta'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'Session'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': '_tag'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'Tag'}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'q'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'TagSemanticTag'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'q'}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'filter_by'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'tag_id'}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'q'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'order_by'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'attribute', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': '_tag'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'Tag'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'tags'}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'all'}, {'id': '63', 'type': 'argument_list', 'children': []}; {'id': '64', 'type': 'return_statement', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'tags'} | def tags(self):
'''Return a list of all tags that have this semantic tag, sorted by name.
:rtype: list of ckan.model.tag.Tag objects
'''
q = meta.Session.query(_tag.Tag)
q = q.join(TagSemanticTag)
q = q.filter_by(tag_id=self.id)
q = q.order_by(_tag.Tag.name)
tags = q.all()
return tags |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'ERROR', 'children': ['2', '178', '195', '203', '213']}; {'id': '2', 'type': 'function_definition', 'children': ['3', '4', '10']}, {'id': '3', 'type': 'function_name', 'children': [], 'value': 'make_feature_bed'}; {'id': '4', 'type': 'parameters', 'children': ['5', '6', '7']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'gtf'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'feature'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '15']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'bed_lines'}; {'id': '14', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '15', 'type': 'with_statement', 'children': ['16', '25']}; {'id': '16', 'type': 'with_clause', 'children': ['17']}, {'id': '17', 'type': 'with_item', 'children': ['18']}; {'id': '18', 'type': 'as_pattern', 'children': ['19', '23']}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'open'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'gtf'}, {'id': '23', 'type': 'as_pattern_target', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '25', 'type': 'block', 'children': ['26', '38', '166']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '29', 'type': 'call', 'children': ['30', '37']}; {'id': '30', 'type': 'attribute', 'children': ['31', '36']}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'readline'}, {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '37', 'type': 'argument_list', 'children': []}; {'id': '38', 'type': 'while_statement', 'children': ['39', '42', '49']}, {'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': '!='}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '41', 'type': 'string', 'children': [], 'value': "''"}; {'id': '42', 'type': 'ERROR', 'children': ['43', '46', '47']}, {'id': '43', 'type': 'subscript', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '45', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '46', 'type': 'string', 'children': [], 'value': "'\n line = line.split('"}, {'id': '47', 'type': 'ERROR', 'children': ['48']}; {'id': '48', 'type': 'escape_sequence', 'children': [], 'value': '\\t'}, {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'if_statement', 'children': ['51', '56']}, {'id': '51', 'type': 'comparison_operator', 'children': ['52', '55'], 'value': '=='}; {'id': '52', 'type': 'subscript', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '54', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'feature'}; {'id': '56', 'type': 'block', 'children': ['57', '63', '77', '83', '140', '146']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'chrom'}; {'id': '60', 'type': 'subscript', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '62', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'binary_operator', 'children': ['70', '76'], 'value': '-'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'subscript', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '75', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '76', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '80', 'type': 'subscript', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '82', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '83', 'type': 'if_statement', 'children': ['84', '87', '113']}; {'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': '=='}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'feature'}; {'id': '86', 'type': 'string', 'children': [], 'value': "'gene'"}, {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '91', 'type': 'call', 'children': ['92', '111']}; {'id': '92', 'type': 'attribute', 'children': ['93', '110']}, {'id': '93', 'type': 'subscript', 'children': ['94', '109']}; {'id': '94', 'type': 'call', 'children': ['95', '107']}, {'id': '95', 'type': 'attribute', 'children': ['96', '106']}; {'id': '96', 'type': 'subscript', 'children': ['97', '105']}, {'id': '97', 'type': 'call', 'children': ['98', '103']}; {'id': '98', 'type': 'attribute', 'children': ['99', '102']}, {'id': '99', 'type': 'subscript', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '101', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'string', 'children': [], 'value': "';'"}, {'id': '105', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '109', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'string', 'children': [], 'value': '\'"\''}, {'id': '113', 'type': 'else_clause', 'children': ['114']}; {'id': '114', 'type': 'block', 'children': ['115']}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '118', 'type': 'call', 'children': ['119', '138']}, {'id': '119', 'type': 'attribute', 'children': ['120', '137']}; {'id': '120', 'type': 'subscript', 'children': ['121', '136']}, {'id': '121', 'type': 'call', 'children': ['122', '134']}; {'id': '122', 'type': 'attribute', 'children': ['123', '133']}, {'id': '123', 'type': 'subscript', 'children': ['124', '132']}; {'id': '124', 'type': 'call', 'children': ['125', '130']}, {'id': '125', 'type': 'attribute', 'children': ['126', '129']}; {'id': '126', 'type': 'subscript', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '128', 'type': 'integer', 'children': [], 'value': '8'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'string', 'children': [], 'value': "';'"}; {'id': '132', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}, {'id': '135', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '136', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'string', 'children': [], 'value': '\'"\''}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'strand'}, {'id': '143', 'type': 'subscript', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '145', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'call', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'bed_lines'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'binary_operator', 'children': ['153', '165'], 'value': '+'}, {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'string', 'children': [], 'value': "'\\t'"}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'list', 'children': ['159', '160', '161', '162', '163', '164'], 'value': "[chrom, start, end, name, '.',\n strand]"}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'chrom'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '163', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'strand'}, {'id': '165', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'assignment', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '169', 'type': 'call', 'children': ['170', '177']}; {'id': '170', 'type': 'attribute', 'children': ['171', '176']}, {'id': '171', 'type': 'call', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'readline'}, {'id': '175', 'type': 'argument_list', 'children': []}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '177', 'type': 'argument_list', 'children': []}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'assignment', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'bt'}, {'id': '181', 'type': 'call', 'children': ['182', '185']}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'pbt'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'BedTool'}, {'id': '185', 'type': 'argument_list', 'children': ['186', '192']}; {'id': '186', 'type': 'call', 'children': ['187', '190']}, {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'string', 'children': [], 'value': "''"}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'bed_lines'}; {'id': '192', 'type': 'keyword_argument', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'from_string'}; {'id': '194', 'type': 'True', 'children': []}, {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'assignment', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'bt'}; {'id': '198', 'type': 'call', 'children': ['199', '202']}, {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'bt'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '202', 'type': 'argument_list', 'children': []}, {'id': '203', 'type': 'if_statement', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '205', 'type': 'block', 'children': ['206']}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}, {'id': '207', 'type': 'call', 'children': ['208', '211']}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'bt'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'saveas'}, {'id': '211', 'type': 'argument_list', 'children': ['212']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '213', 'type': 'return_statement', 'children': ['214']} | def make_feature_bed(gtf, feature, out=None):
bed_lines = []
with open(gtf) as f:
line = f.readline().strip()
while line != '':
if line[0] != '
line = line.split('\t')
if line[2] == feature:
chrom = line[0]
start = str(int(line[3]) - 1)
end = line[4]
if feature == 'gene':
name = line[8].split(';')[0].split(' ')[1].strip('"')
else:
name = line[8].split(';')[1].split(' ')[2].strip('"')
strand = line[6]
bed_lines.append('\t'.join([chrom, start, end, name, '.',
strand]) + '\n')
line = f.readline().strip()
bt = pbt.BedTool(''.join(bed_lines), from_string=True)
bt = bt.sort()
if out:
bt.saveas(out)
return bt |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'order_by'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '11', 'type': 'dictionary_splat_pattern', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'with_statement', 'children': ['15', '23']}, {'id': '15', 'type': 'with_clause', 'children': ['16']}; {'id': '16', 'type': 'with_item', 'children': ['17']}, {'id': '17', 'type': 'as_pattern', 'children': ['18', '21']}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'rconnect'}; {'id': '20', 'type': 'argument_list', 'children': []}, {'id': '21', 'type': 'as_pattern_target', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'conn'}, {'id': '23', 'type': 'block', 'children': ['24', '34']}; {'id': '24', 'type': 'if_statement', 'children': ['25', '31']}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '30'], 'value': '=='}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'raise_statement', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '34', 'type': 'try_statement', 'children': ['35', '99', '113', '127']}, {'id': '35', 'type': 'block', 'children': ['36', '44', '53', '68', '83', '90']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': '_base'}, {'id': '43', 'type': 'argument_list', 'children': []}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'filter'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '53', 'type': 'if_statement', 'children': ['54', '57']}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'is'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'order_by'}; {'id': '56', 'type': 'None', 'children': []}, {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': '_order_by'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'order_by'}; {'id': '68', 'type': 'if_statement', 'children': ['69', '72']}, {'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': '>'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '71', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'query'}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': '_limit'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'rv'}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'run'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'conn'}, {'id': '99', 'type': 'except_clause', 'children': ['100', '104']}; {'id': '100', 'type': 'as_pattern', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'ReqlOpFailedError'}; {'id': '102', 'type': 'as_pattern_target', 'children': ['103']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '104', 'type': 'block', 'children': ['105', '112']}, {'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': 'log'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '112', 'type': 'raise_statement', 'children': []}, {'id': '113', 'type': 'except_clause', 'children': ['114', '118']}; {'id': '114', 'type': 'as_pattern', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '116', 'type': 'as_pattern_target', 'children': ['117']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '118', 'type': 'block', 'children': ['119', '126']}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'call', 'children': ['121', '124']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '126', 'type': 'raise_statement', 'children': []}, {'id': '127', 'type': 'else_clause', 'children': ['128']}; {'id': '128', 'type': 'block', 'children': ['129', '142']}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '132', 'type': 'list_comprehension', 'children': ['133', '139']}, {'id': '133', 'type': 'call', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': '_model'}, {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '139', 'type': 'for_in_clause', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'rv'}; {'id': '142', 'type': 'return_statement', 'children': ['143']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'data'} | def filter(self, order_by=None, limit=0, **kwargs):
with rconnect() as conn:
if len(kwargs) == 0:
raise ValueError
try:
query = self._base()
query = query.filter(kwargs)
if order_by is not None:
query = self._order_by(query, order_by)
if limit > 0:
query = self._limit(query, limit)
log.debug(query)
rv = query.run(conn)
except ReqlOpFailedError as e:
log.warn(e)
raise
except Exception as e:
log.warn(e)
raise
else:
data = [self._model(_) for _ in rv]
return data |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'all'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'order_by'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'with_statement', 'children': ['13', '21']}, {'id': '13', 'type': 'with_clause', 'children': ['14']}; {'id': '14', 'type': 'with_item', 'children': ['15']}, {'id': '15', 'type': 'as_pattern', 'children': ['16', '19']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'rconnect'}; {'id': '18', 'type': 'argument_list', 'children': []}, {'id': '19', 'type': 'as_pattern_target', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'conn'}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'try_statement', 'children': ['23', '78', '92']}, {'id': '23', 'type': 'block', 'children': ['24', '32', '47', '62', '69']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'query'}, {'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': '_base'}, {'id': '31', 'type': 'argument_list', 'children': []}; {'id': '32', 'type': 'if_statement', 'children': ['33', '36']}, {'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': 'is'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'order_by'}, {'id': '35', 'type': 'None', 'children': []}; {'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': 'query'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': '_order_by'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'order_by'}, {'id': '47', 'type': 'if_statement', 'children': ['48', '51']}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': '>'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '50', 'type': 'integer', 'children': [], 'value': '0'}, {'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': 'query'}, {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': '_limit'}, {'id': '59', 'type': 'argument_list', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'rv'}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'conn'}; {'id': '78', 'type': 'except_clause', 'children': ['79', '83']}, {'id': '79', 'type': 'as_pattern', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '81', 'type': 'as_pattern_target', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '83', 'type': 'block', 'children': ['84', '91']}; {'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': 'log'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'warn'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '91', 'type': 'raise_statement', 'children': []}; {'id': '92', 'type': 'else_clause', 'children': ['93']}, {'id': '93', 'type': 'block', 'children': ['94', '107']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '97', 'type': 'list_comprehension', 'children': ['98', '104']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': '_model'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '104', 'type': 'for_in_clause', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'rv'}, {'id': '107', 'type': 'return_statement', 'children': ['108']} | def all(self, order_by=None, limit=0):
with rconnect() as conn:
try:
query = self._base()
if order_by is not None:
query = self._order_by(query, order_by)
if limit > 0:
query = self._limit(query, limit)
log.debug(query)
rv = query.run(conn)
except Exception as e:
log.warn(e)
raise
else:
data = [self._model(_) for _ in rv]
return data |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'safe_dump_js'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'js'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'abspath'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'fastmode'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'compress'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'enable_verbose'}; {'id': '14', 'type': 'True', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16', '23', '29', '47']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'abspath'}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'abspath'}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'temp_abspath'}; {'id': '26', 'type': 'binary_operator', 'children': ['27', '28'], 'value': '%'}, {'id': '27', 'type': 'string', 'children': [], 'value': '"%s.tmp"'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'abspath'}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'dump_js'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34', '35', '38', '41', '44']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'js'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'temp_abspath'}, {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'fastmode'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'fastmode'}; {'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '40', 'type': 'True', 'children': []}, {'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'compress'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'compress'}; {'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'enable_verbose'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'enable_verbose'}, {'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': 'shutil'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'move'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'temp_abspath'} | def safe_dump_js(js, abspath,
fastmode=False, compress=False, enable_verbose=True):
abspath = str(abspath)
temp_abspath = "%s.tmp" % abspath
dump_js(js, temp_abspath, fastmode=fastmode,
replace=True, compress=compress, enable_verbose=enable_verbose)
shutil.move(temp_abspath, abspath) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'all_selectors'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'Class'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '22', '31', '64', '77']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'selectors'}; {'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': 'cssparser'}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'cssutils'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'CSSParser'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'validate'}, {'id': '21', 'type': 'False', 'children': []}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'css'}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'cssparser'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'parseFile'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'fn'}, {'id': '31', 'type': 'for_statement', 'children': ['32', '33', '51']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'rule'}, {'id': '33', 'type': 'list_comprehension', 'children': ['34', '35', '40']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '35', 'type': 'for_in_clause', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'css'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'cssRules'}; {'id': '40', 'type': 'if_clause', 'children': ['41']}, {'id': '41', 'type': 'comparison_operator', 'children': ['42', '46'], 'value': '=='}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '46', 'type': 'attribute', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'cssutils'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'css'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'CSSStyleRule'}, {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'augmented_assignment', 'children': ['54', '55'], 'value': '+='}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'selectors'}, {'id': '55', 'type': 'list_comprehension', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'sel'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'selectorText'}, {'id': '59', 'type': 'for_in_clause', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'sel'}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'rule'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'selectorList'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'selectors'}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'selectors'}, {'id': '77', 'type': 'return_statement', 'children': ['78']} | def all_selectors(Class, fn):
selectors = []
cssparser = cssutils.CSSParser(validate=False)
css = cssparser.parseFile(fn)
for rule in [r for r in css.cssRules if type(r)==cssutils.css.CSSStyleRule]:
selectors += [sel.selectorText for sel in rule.selectorList]
selectors = sorted(list(set(selectors)))
return selectors |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_logger'}, {'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': 'args'}, {'id': '7', 'type': 'dictionary', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '18', '26', '46', '56', '65', '78', '85', '92', '138', '156']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'getLogger'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'string', 'children': [], 'value': '"SmartFileSorter"'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'level'}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'INFO'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '36']}, {'id': '27', 'type': 'boolean_operator', 'children': ['28', '31'], 'value': 'and'}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'in'}, {'id': '29', 'type': 'string', 'children': [], 'value': "'--debug'"}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '31', 'type': 'comparison_operator', 'children': ['32', '35'], 'value': 'is'}; {'id': '32', 'type': 'subscript', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'--debug'"}, {'id': '35', 'type': 'True', 'children': []}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'setLevel'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'DEBUG'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'file_log_formatter'}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'Formatter'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '55']}; {'id': '54', 'type': 'string', 'children': [], 'value': "'%(asctime)s %(name)s %(levelname)s %(message)s'"}, {'id': '55', 'type': 'string', 'children': [], 'value': "'%Y-%m-%d %H:%M:%S'"}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'console_log_formatter'}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'Formatter'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'string', 'children': [], 'value': "'%(message)s'"}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'stdout_stream'}; {'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': 'StreamHandler'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'keyword_argument', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'stream'}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'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': 'stdout_stream'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'setFormatter'}, {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'console_log_formatter'}, {'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': 'addHandler'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'stdout_stream'}; {'id': '92', 'type': 'if_statement', 'children': ['93', '102']}, {'id': '93', 'type': 'boolean_operator', 'children': ['94', '97'], 'value': 'and'}; {'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': 'in'}, {'id': '95', 'type': 'string', 'children': [], 'value': "'--log'"}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '97', 'type': 'comparison_operator', 'children': ['98', '101'], 'value': 'is'}; {'id': '98', 'type': 'subscript', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '100', 'type': 'string', 'children': [], 'value': "'--log'"}, {'id': '101', 'type': 'None', 'children': []}; {'id': '102', 'type': 'block', 'children': ['103', '113', '124', '131']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'logfile'}; {'id': '106', 'type': 'call', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '108', 'type': 'argument_list', 'children': ['109', '112']}, {'id': '109', 'type': 'subscript', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '111', 'type': 'string', 'children': [], 'value': "'--log'"}; {'id': '112', 'type': 'string', 'children': [], 'value': "'w'"}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'logfile_stream'}; {'id': '116', 'type': 'call', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'StreamHandler'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'keyword_argument', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'stream'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'logfile'}; {'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': 'logfile_stream'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'setFormatter'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'file_log_formatter'}, {'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': 'logger'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'addHandler'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'logfile_stream'}; {'id': '138', 'type': 'if_statement', 'children': ['139', '148']}, {'id': '139', 'type': 'boolean_operator', 'children': ['140', '143'], 'value': 'and'}; {'id': '140', 'type': 'comparison_operator', 'children': ['141', '142'], 'value': 'in'}, {'id': '141', 'type': 'string', 'children': [], 'value': "'--dry-run'"}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '143', 'type': 'comparison_operator', 'children': ['144', '147'], 'value': 'is'}; {'id': '144', 'type': 'subscript', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '146', 'type': 'string', 'children': [], 'value': "'--dry-run'"}, {'id': '147', 'type': 'True', 'children': []}; {'id': '148', 'type': 'block', 'children': ['149']}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'call', 'children': ['151', '154']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}, {'id': '155', 'type': 'string', 'children': [], 'value': "'Running with --dry-run parameter. Actions will not be performed.'"}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'logger'} | def create_logger(self, args={}):
logger = logging.getLogger("SmartFileSorter")
logger.level = logging.INFO
if '--debug' in args and args['--debug'] is True:
logger.setLevel(logging.DEBUG)
file_log_formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s',
'%Y-%m-%d %H:%M:%S')
console_log_formatter = logging.Formatter('%(message)s')
stdout_stream = logging.StreamHandler(stream=sys.stdout)
stdout_stream.setFormatter(console_log_formatter)
logger.addHandler(stdout_stream)
if '--log' in args and args['--log'] is not None:
logfile = open(args['--log'], 'w')
logfile_stream = logging.StreamHandler(stream=logfile)
logfile_stream.setFormatter(file_log_formatter)
logger.addHandler(logfile_stream)
if '--dry-run' in args and args['--dry-run'] is True:
logger.info('Running with --dry-run parameter. Actions will not be performed.')
self.logger = logger |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'slug'}; {'id': '6', 'type': 'block', 'children': ['7', '16', '21', '29', '42', '55', '68', '81', '94', '107', '115', '123', '167']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'kb'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'api'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'get_kb_by_slug'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'slug'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'check_knowledge_access'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'kb'}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'reqparse'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'RequestParser'}; {'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': 'parser'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'add_argument'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36', '39']}, {'id': '35', 'type': 'string', 'children': [], 'value': "'from'"}; {'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'help'}, {'id': '41', 'type': 'string', 'children': [], 'value': '"Return only entries where key matches this."'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'add_argument'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '49', '52']}; {'id': '48', 'type': 'string', 'children': [], 'value': "'to'"}, {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '54', 'type': 'string', 'children': [], 'value': '"Return only entries where value matches this."'}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'parser'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'add_argument'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '62', '65']}, {'id': '61', 'type': 'string', 'children': [], 'value': "'page'"}; {'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'help'}, {'id': '67', 'type': 'string', 'children': [], 'value': '"Require a specific page"'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'add_argument'}, {'id': '73', 'type': 'argument_list', 'children': ['74', '75', '78']}; {'id': '74', 'type': 'string', 'children': [], 'value': "'per_page'"}, {'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '80', 'type': 'string', 'children': [], 'value': '"Set how much result per page"'}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'parser'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'add_argument'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '88', '91']}, {'id': '87', 'type': 'string', 'children': [], 'value': "'match_type'"}; {'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'help'}, {'id': '93', 'type': 'string', 'children': [], 'value': '"s=substring, e=exact, sw=startswith"'}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'add_argument'}, {'id': '99', 'type': 'argument_list', 'children': ['100', '101', '104']}; {'id': '100', 'type': 'string', 'children': [], 'value': "'sortby'"}, {'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'help'}; {'id': '106', 'type': 'string', 'children': [], 'value': '"the sorting criteria (\'from\' or \'to\')"'}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '110', 'type': 'call', 'children': ['111', '114']}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'parser'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'parse_args'}; {'id': '114', 'type': 'argument_list', 'children': []}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'kb_dict'}; {'id': '118', 'type': 'call', 'children': ['119', '122']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'kb'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'to_dict'}; {'id': '122', 'type': 'argument_list', 'children': []}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '128']}, {'id': '125', 'type': 'subscript', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'kb_dict'}, {'id': '127', 'type': 'string', 'children': [], 'value': "'mappings'"}; {'id': '128', 'type': 'call', 'children': ['129', '133']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131', '132']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'KnwKBMappingsResource'}, {'id': '131', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'search_mappings'}, {'id': '133', 'type': 'argument_list', 'children': ['134', '137', '142', '147', '152', '157', '162']}; {'id': '134', 'type': 'keyword_argument', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'kb'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'kb'}, {'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '141', 'type': 'string', 'children': [], 'value': "'from'"}; {'id': '142', 'type': 'keyword_argument', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '144', 'type': 'subscript', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '146', 'type': 'string', 'children': [], 'value': "'to'"}, {'id': '147', 'type': 'keyword_argument', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'match_type'}, {'id': '149', 'type': 'subscript', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '151', 'type': 'string', 'children': [], 'value': "'match_type'"}; {'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'sortby'}; {'id': '154', 'type': 'subscript', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '156', 'type': 'string', 'children': [], 'value': "'sortby'"}, {'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'page'}, {'id': '159', 'type': 'subscript', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '161', 'type': 'string', 'children': [], 'value': "'page'"}; {'id': '162', 'type': 'keyword_argument', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'per_page'}; {'id': '164', 'type': 'subscript', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '166', 'type': 'string', 'children': [], 'value': "'per_page'"}, {'id': '167', 'type': 'return_statement', 'children': ['168']} | def get(self, slug):
kb = api.get_kb_by_slug(slug)
check_knowledge_access(kb)
parser = reqparse.RequestParser()
parser.add_argument(
'from', type=str,
help="Return only entries where key matches this.")
parser.add_argument(
'to', type=str,
help="Return only entries where value matches this.")
parser.add_argument('page', type=int,
help="Require a specific page")
parser.add_argument('per_page', type=int,
help="Set how much result per page")
parser.add_argument('match_type', type=str,
help="s=substring, e=exact, sw=startswith")
parser.add_argument('sortby', type=str,
help="the sorting criteria ('from' or 'to')")
args = parser.parse_args()
kb_dict = kb.to_dict()
kb_dict['mappings'] = KnwKBMappingsResource \
.search_mappings(kb=kb, key=args['from'], value=args['to'],
match_type=args['match_type'],
sortby=args['sortby'], page=args['page'],
per_page=args['per_page'])
return kb_dict |
Subsets and Splits