sequence
stringlengths
1.19k
35k
code
stringlengths
75
8.58k
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '32']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'usearch_chimera_filter_de_novo'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fasta_filepath'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'output_chimera_filepath'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'output_non_chimera_filepath'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'abundance_skew'}, {'id': '13', 'type': 'float', 'children': [], 'value': '2.0'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'log_name'}; {'id': '16', 'type': 'string', 'children': [], 'value': '"uchime_de_novo_chimera_filtering.log"'}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'usersort'}, {'id': '19', 'type': 'False', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}; {'id': '22', 'type': 'False', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'save_intermediate_files'}, {'id': '25', 'type': 'False', 'children': []}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'remove_usearch_logs'}; {'id': '28', 'type': 'False', 'children': []}, {'id': '29', 'type': 'default_parameter', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'working_dir'}, {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'block', 'children': ['33', '51', '69', '77', '84', '97', '110', '123', '133', '140', '150']}, {'id': '33', 'type': 'if_statement', 'children': ['34', '36']}; {'id': '34', 'type': 'not_operator', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'output_chimera_filepath'}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '42']}, {'id': '39', 'type': 'pattern_list', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'output_chimera_filepath'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'mkstemp'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '48']}, {'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '47', 'type': 'string', 'children': [], 'value': "'uchime_chimeras_'"}; {'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'suffix'}; {'id': '50', 'type': 'string', 'children': [], 'value': "'.fasta'"}, {'id': '51', 'type': 'if_statement', 'children': ['52', '54']}; {'id': '52', 'type': 'not_operator', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'output_non_chimera_filepath'}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '60']}, {'id': '57', 'type': 'pattern_list', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'output_non_chimera_filepath'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'mkstemp'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '66']}, {'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '65', 'type': 'string', 'children': [], 'value': "'uchime_non_chimeras_'"}; {'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'suffix'}; {'id': '68', 'type': 'string', 'children': [], 'value': "'.fasta'"}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'log_filepath'}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '74', 'type': 'argument_list', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'working_dir'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'log_name'}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '80', 'type': 'dictionary', 'children': ['81']}, {'id': '81', 'type': 'pair', 'children': ['82', '83']}; {'id': '82', 'type': 'string', 'children': [], 'value': "'--abskew'"}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'abundance_skew'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'Usearch'}, {'id': '89', 'type': 'argument_list', 'children': ['90', '91', '94']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'WorkingDir'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'working_dir'}; {'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}, {'id': '97', 'type': 'if_statement', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'usersort'}, {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'call', 'children': ['102', '109']}; {'id': '102', 'type': 'attribute', 'children': ['103', '108']}, {'id': '103', 'type': 'subscript', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'Parameters'}, {'id': '107', 'type': 'string', 'children': [], 'value': "'--usersort'"}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'on'}, {'id': '109', 'type': 'argument_list', 'children': []}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '113', 'type': 'dictionary', 'children': ['114', '117', '120']}; {'id': '114', 'type': 'pair', 'children': ['115', '116']}, {'id': '115', 'type': 'string', 'children': [], 'value': "'--uchime'"}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'fasta_filepath'}, {'id': '117', 'type': 'pair', 'children': ['118', '119']}; {'id': '118', 'type': 'string', 'children': [], 'value': "'--chimeras'"}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'output_chimera_filepath'}; {'id': '120', 'type': 'pair', 'children': ['121', '122']}, {'id': '121', 'type': 'string', 'children': [], 'value': "'--nonchimeras'"}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'output_non_chimera_filepath'}, {'id': '123', 'type': 'if_statement', 'children': ['124', '126']}; {'id': '124', 'type': 'not_operator', 'children': ['125']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'remove_usearch_logs'}; {'id': '126', 'type': 'block', 'children': ['127']}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '132']}, {'id': '129', 'type': 'subscript', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '131', 'type': 'string', 'children': [], 'value': "'--log'"}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'log_filepath'}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'app_result'}; {'id': '136', 'type': 'call', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '140', 'type': 'if_statement', 'children': ['141', '143']}, {'id': '141', 'type': 'not_operator', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'save_intermediate_files'}, {'id': '143', 'type': 'block', 'children': ['144']}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'remove_files'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'list', 'children': ['149'], 'value': '[output_chimera_filepath]'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'output_chimera_filepath'}; {'id': '150', 'type': 'return_statement', 'children': ['151']}, {'id': '151', 'type': 'expression_list', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'app_result'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'output_non_chimera_filepath'}
def usearch_chimera_filter_de_novo( fasta_filepath, output_chimera_filepath=None, output_non_chimera_filepath=None, abundance_skew=2.0, log_name="uchime_de_novo_chimera_filtering.log", usersort=False, HALT_EXEC=False, save_intermediate_files=False, remove_usearch_logs=False, working_dir=None): if not output_chimera_filepath: _, output_chimera_filepath = mkstemp(prefix='uchime_chimeras_', suffix='.fasta') if not output_non_chimera_filepath: _, output_non_chimera_filepath = mkstemp(prefix='uchime_non_chimeras_', suffix='.fasta') log_filepath = join(working_dir, log_name) params = {'--abskew': abundance_skew} app = Usearch(params, WorkingDir=working_dir, HALT_EXEC=HALT_EXEC) if usersort: app.Parameters['--usersort'].on() data = {'--uchime': fasta_filepath, '--chimeras': output_chimera_filepath, '--nonchimeras': output_non_chimera_filepath } if not remove_usearch_logs: data['--log'] = log_filepath app_result = app(data) if not save_intermediate_files: remove_files([output_chimera_filepath]) return app_result, output_non_chimera_filepath
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '56']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'usearch_cluster_seqs_ref'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32', '35', '38', '41', '44', '47', '50', '53']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fasta_filepath'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'output_filepath'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'percent_id'}; {'id': '10', 'type': 'float', 'children': [], 'value': '0.97'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sizein'}, {'id': '13', 'type': 'True', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'sizeout'}; {'id': '16', 'type': 'True', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'w'}, {'id': '19', 'type': 'integer', 'children': [], 'value': '64'}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'slots'}; {'id': '22', 'type': 'integer', 'children': [], 'value': '16769023'}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'maxrejects'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '64'}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'log_name'}; {'id': '28', 'type': 'string', 'children': [], 'value': '"usearch_cluster_seqs.log"'}, {'id': '29', 'type': 'default_parameter', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'usersort'}, {'id': '31', 'type': 'True', 'children': []}; {'id': '32', 'type': 'default_parameter', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}; {'id': '34', 'type': 'False', 'children': []}, {'id': '35', 'type': 'default_parameter', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'save_intermediate_files'}, {'id': '37', 'type': 'False', 'children': []}; {'id': '38', 'type': 'default_parameter', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'remove_usearch_logs'}; {'id': '40', 'type': 'False', 'children': []}, {'id': '41', 'type': 'default_parameter', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'suppress_new_clusters'}, {'id': '43', 'type': 'False', 'children': []}; {'id': '44', 'type': 'default_parameter', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'refseqs_fp'}; {'id': '46', 'type': 'None', 'children': []}, {'id': '47', 'type': 'default_parameter', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'output_dir'}, {'id': '49', 'type': 'None', 'children': []}; {'id': '50', 'type': 'default_parameter', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'working_dir'}; {'id': '52', 'type': 'None', 'children': []}, {'id': '53', 'type': 'default_parameter', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'rev'}, {'id': '55', 'type': 'False', 'children': []}; {'id': '56', 'type': 'block', 'children': ['57', '75', '83', '91', '113', '126', '139', '152', '165', '175', '182', '186', '362', '371']}, {'id': '57', 'type': 'if_statement', 'children': ['58', '60']}; {'id': '58', 'type': 'not_operator', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'output_filepath'}; {'id': '60', 'type': 'block', 'children': ['61']}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '66']}, {'id': '63', 'type': 'pattern_list', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'output_filepath'}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'mkstemp'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '72']}, {'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '71', 'type': 'string', 'children': [], 'value': "'usearch_cluster_ref_based'"}; {'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'suffix'}; {'id': '74', 'type': 'string', 'children': [], 'value': "'.uc'"}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'log_filepath'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'working_dir'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'log_name'}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'uc_filepath'}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'working_dir'}; {'id': '90', 'type': 'string', 'children': [], 'value': '"clustered_seqs_post_chimera.uc"'}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '94', 'type': 'dictionary', 'children': ['95', '98', '101', '104', '107', '110']}, {'id': '95', 'type': 'pair', 'children': ['96', '97']}; {'id': '96', 'type': 'string', 'children': [], 'value': "'--sizein'"}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'sizein'}; {'id': '98', 'type': 'pair', 'children': ['99', '100']}, {'id': '99', 'type': 'string', 'children': [], 'value': "'--sizeout'"}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'sizeout'}, {'id': '101', 'type': 'pair', 'children': ['102', '103']}; {'id': '102', 'type': 'string', 'children': [], 'value': "'--id'"}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'percent_id'}; {'id': '104', 'type': 'pair', 'children': ['105', '106']}, {'id': '105', 'type': 'string', 'children': [], 'value': "'--w'"}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'w'}, {'id': '107', 'type': 'pair', 'children': ['108', '109']}; {'id': '108', 'type': 'string', 'children': [], 'value': "'--slots'"}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'slots'}; {'id': '110', 'type': 'pair', 'children': ['111', '112']}, {'id': '111', 'type': 'string', 'children': [], 'value': "'--maxrejects'"}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'maxrejects'}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '116', 'type': 'call', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'Usearch'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120', '123']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'WorkingDir'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'working_dir'}, {'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}; {'id': '126', 'type': 'if_statement', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'usersort'}; {'id': '128', 'type': 'block', 'children': ['129']}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'call', 'children': ['131', '138']}, {'id': '131', 'type': 'attribute', 'children': ['132', '137']}; {'id': '132', 'type': 'subscript', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'Parameters'}; {'id': '136', 'type': 'string', 'children': [], 'value': "'--usersort'"}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'on'}; {'id': '138', 'type': 'argument_list', 'children': []}, {'id': '139', 'type': 'if_statement', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'rev'}, {'id': '141', 'type': 'block', 'children': ['142']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'call', 'children': ['144', '151']}; {'id': '144', 'type': 'attribute', 'children': ['145', '150']}, {'id': '145', 'type': 'subscript', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'Parameters'}, {'id': '149', 'type': 'string', 'children': [], 'value': "'--rev'"}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'on'}, {'id': '151', 'type': 'argument_list', 'children': []}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '155', 'type': 'dictionary', 'children': ['156', '159', '162']}; {'id': '156', 'type': 'pair', 'children': ['157', '158']}, {'id': '157', 'type': 'string', 'children': [], 'value': "'--query'"}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'fasta_filepath'}, {'id': '159', 'type': 'pair', 'children': ['160', '161']}; {'id': '160', 'type': 'string', 'children': [], 'value': "'--uc'"}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'uc_filepath'}; {'id': '162', 'type': 'pair', 'children': ['163', '164']}, {'id': '163', 'type': 'string', 'children': [], 'value': "'--db'"}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'refseqs_fp'}, {'id': '165', 'type': 'if_statement', 'children': ['166', '168']}; {'id': '166', 'type': 'not_operator', 'children': ['167']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'remove_usearch_logs'}; {'id': '168', 'type': 'block', 'children': ['169']}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '174']}, {'id': '171', 'type': 'subscript', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '173', 'type': 'string', 'children': [], 'value': "'--log'"}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'log_filepath'}, {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'assignment', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'app_result'}; {'id': '178', 'type': 'call', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '180', 'type': 'argument_list', 'children': ['181']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'files_to_remove'}, {'id': '185', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '186', 'type': 'if_statement', 'children': ['187', '188', '223']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'suppress_new_clusters'}; {'id': '188', 'type': 'block', 'children': ['189', '197', '216']}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'output_fna_filepath'}; {'id': '192', 'type': 'call', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '194', 'type': 'argument_list', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '196', 'type': 'string', 'children': [], 'value': "'ref_clustered_seqs.fasta'"}, {'id': '197', 'type': 'expression_statement', 'children': ['198']}; {'id': '198', 'type': 'assignment', 'children': ['199', '202']}, {'id': '199', 'type': 'pattern_list', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'output_filepath'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'labels_hits'}; {'id': '202', 'type': 'call', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'get_fasta_from_uc_file'}; {'id': '204', 'type': 'argument_list', 'children': ['205', '206', '207', '210', '213']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'fasta_filepath'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'uc_filepath'}, {'id': '207', 'type': 'keyword_argument', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'hit_type'}, {'id': '209', 'type': 'string', 'children': [], 'value': '"H"'}; {'id': '210', 'type': 'keyword_argument', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'output_dir'}, {'id': '213', 'type': 'keyword_argument', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'output_fna_filepath'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'output_fna_filepath'}; {'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': 'files_to_remove'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'uc_filepath'}, {'id': '223', 'type': 'else_clause', 'children': ['224']}; {'id': '224', 'type': 'block', 'children': ['225', '233', '253', '262', '282', '326', '341', '348', '355']}, {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'output_fna_clustered'}; {'id': '228', 'type': 'call', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '230', 'type': 'argument_list', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '232', 'type': 'string', 'children': [], 'value': "'ref_clustered_seqs.fasta'"}, {'id': '233', 'type': 'expression_statement', 'children': ['234']}; {'id': '234', 'type': 'assignment', 'children': ['235', '238', '239']}, {'id': '235', 'type': 'pattern_list', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'output_filepath_ref_clusters'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'labels_hits'}; {'id': '238', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '239', 'type': 'call', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'get_fasta_from_uc_file'}, {'id': '241', 'type': 'argument_list', 'children': ['242', '243', '244', '247', '250']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'fasta_filepath'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'uc_filepath'}; {'id': '244', 'type': 'keyword_argument', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'hit_type'}; {'id': '246', 'type': 'string', 'children': [], 'value': '"H"'}, {'id': '247', 'type': 'keyword_argument', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'output_dir'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '250', 'type': 'keyword_argument', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'output_fna_filepath'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'output_fna_clustered'}, {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'assignment', 'children': ['255', '256', '257']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'output_fna_failures'}; {'id': '256', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '257', 'type': 'call', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '259', 'type': 'argument_list', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'output_dir'}, {'id': '261', 'type': 'string', 'children': [], 'value': "'ref_clustered_seqs_failures.fasta'"}; {'id': '262', 'type': 'expression_statement', 'children': ['263']}, {'id': '263', 'type': 'assignment', 'children': ['264', '267', '268']}; {'id': '264', 'type': 'pattern_list', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'output_filepath_failures'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'labels_hits'}, {'id': '267', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '268', 'type': 'call', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'get_fasta_from_uc_file'}; {'id': '270', 'type': 'argument_list', 'children': ['271', '272', '273', '276', '279']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'fasta_filepath'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'uc_filepath'}, {'id': '273', 'type': 'keyword_argument', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'hit_type'}, {'id': '275', 'type': 'string', 'children': [], 'value': '"N"'}; {'id': '276', 'type': 'keyword_argument', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'output_dir'}, {'id': '279', 'type': 'keyword_argument', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'output_fna_filepath'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'output_fna_failures'}; {'id': '282', 'type': 'expression_statement', 'children': ['283']}, {'id': '283', 'type': 'assignment', 'children': ['284', '287', '288']}; {'id': '284', 'type': 'pattern_list', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'app_result'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'output_filepath_clustered_failures'}, {'id': '287', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '288', 'type': 'call', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'usearch_cluster_seqs'}; {'id': '290', 'type': 'argument_list', 'children': ['291', '292', '299', '302', '305', '308', '311', '314', '317', '320', '323']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'output_fna_failures'}; {'id': '292', 'type': 'keyword_argument', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'output_filepath'}; {'id': '294', 'type': 'call', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '296', 'type': 'argument_list', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '298', 'type': 'string', 'children': [], 'value': "'clustered_seqs_reference_failures.fasta'"}, {'id': '299', 'type': 'keyword_argument', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'percent_id'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'percent_id'}; {'id': '302', 'type': 'keyword_argument', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'sizein'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'sizein'}, {'id': '305', 'type': 'keyword_argument', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'sizeout'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'sizeout'}; {'id': '308', 'type': 'keyword_argument', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'w'}, {'id': '311', 'type': 'keyword_argument', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'slots'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'slots'}; {'id': '314', 'type': 'keyword_argument', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'maxrejects'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'maxrejects'}, {'id': '317', 'type': 'keyword_argument', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'save_intermediate_files'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'save_intermediate_files'}; {'id': '320', 'type': 'keyword_argument', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'remove_usearch_logs'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'remove_usearch_logs'}, {'id': '323', 'type': 'keyword_argument', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'working_dir'}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'working_dir'}; {'id': '326', 'type': 'expression_statement', 'children': ['327']}, {'id': '327', 'type': 'assignment', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'output_filepath'}, {'id': '329', 'type': 'call', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'concatenate_fastas'}, {'id': '331', 'type': 'argument_list', 'children': ['332', '333', '334']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'output_fna_clustered'}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'output_fna_failures'}; {'id': '334', 'type': 'keyword_argument', 'children': ['335', '336']}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'output_concat_filepath'}; {'id': '336', 'type': 'call', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '338', 'type': 'argument_list', 'children': ['339', '340']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '340', 'type': 'string', 'children': [], 'value': "'concatenated_reference_denovo_clusters.fasta'"}, {'id': '341', 'type': 'expression_statement', 'children': ['342']}; {'id': '342', 'type': 'call', 'children': ['343', '346']}, {'id': '343', 'type': 'attribute', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'files_to_remove'}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '346', 'type': 'argument_list', 'children': ['347']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'output_fna_clustered'}; {'id': '348', 'type': 'expression_statement', 'children': ['349']}, {'id': '349', 'type': 'call', 'children': ['350', '353']}; {'id': '350', 'type': 'attribute', 'children': ['351', '352']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'files_to_remove'}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '353', 'type': 'argument_list', 'children': ['354']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'output_fna_failures'}, {'id': '355', 'type': 'expression_statement', 'children': ['356']}; {'id': '356', 'type': 'call', 'children': ['357', '360']}, {'id': '357', 'type': 'attribute', 'children': ['358', '359']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'files_to_remove'}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '360', 'type': 'argument_list', 'children': ['361']}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'output_filepath_clustered_failures'}; {'id': '362', 'type': 'if_statement', 'children': ['363', '365']}, {'id': '363', 'type': 'not_operator', 'children': ['364']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'save_intermediate_files'}, {'id': '365', 'type': 'block', 'children': ['366']}; {'id': '366', 'type': 'expression_statement', 'children': ['367']}, {'id': '367', 'type': 'call', 'children': ['368', '369']}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'remove_files'}, {'id': '369', 'type': 'argument_list', 'children': ['370']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'files_to_remove'}, {'id': '371', 'type': 'return_statement', 'children': ['372']}; {'id': '372', 'type': 'expression_list', 'children': ['373', '374']}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'app_result'}
def usearch_cluster_seqs_ref( fasta_filepath, output_filepath=None, percent_id=0.97, sizein=True, sizeout=True, w=64, slots=16769023, maxrejects=64, log_name="usearch_cluster_seqs.log", usersort=True, HALT_EXEC=False, save_intermediate_files=False, remove_usearch_logs=False, suppress_new_clusters=False, refseqs_fp=None, output_dir=None, working_dir=None, rev=False): if not output_filepath: _, output_filepath = mkstemp(prefix='usearch_cluster_ref_based', suffix='.uc') log_filepath = join(working_dir, log_name) uc_filepath = join(working_dir, "clustered_seqs_post_chimera.uc") params = {'--sizein': sizein, '--sizeout': sizeout, '--id': percent_id, '--w': w, '--slots': slots, '--maxrejects': maxrejects} app = Usearch(params, WorkingDir=working_dir, HALT_EXEC=HALT_EXEC) if usersort: app.Parameters['--usersort'].on() if rev: app.Parameters['--rev'].on() data = {'--query': fasta_filepath, '--uc': uc_filepath, '--db': refseqs_fp } if not remove_usearch_logs: data['--log'] = log_filepath app_result = app(data) files_to_remove = [] if suppress_new_clusters: output_fna_filepath = join(output_dir, 'ref_clustered_seqs.fasta') output_filepath, labels_hits = get_fasta_from_uc_file(fasta_filepath, uc_filepath, hit_type="H", output_dir=output_dir, output_fna_filepath=output_fna_filepath) files_to_remove.append(uc_filepath) else: output_fna_clustered = join(output_dir, 'ref_clustered_seqs.fasta') output_filepath_ref_clusters, labels_hits =\ get_fasta_from_uc_file(fasta_filepath, uc_filepath, hit_type="H", output_dir=output_dir, output_fna_filepath=output_fna_clustered) output_fna_failures =\ join(output_dir, 'ref_clustered_seqs_failures.fasta') output_filepath_failures, labels_hits =\ get_fasta_from_uc_file(fasta_filepath, uc_filepath, hit_type="N", output_dir=output_dir, output_fna_filepath=output_fna_failures) app_result, output_filepath_clustered_failures =\ usearch_cluster_seqs(output_fna_failures, output_filepath= join( output_dir, 'clustered_seqs_reference_failures.fasta'), percent_id=percent_id, sizein=sizein, sizeout=sizeout, w=w, slots=slots, maxrejects=maxrejects, save_intermediate_files=save_intermediate_files, remove_usearch_logs=remove_usearch_logs, working_dir=working_dir) output_filepath = concatenate_fastas(output_fna_clustered, output_fna_failures, output_concat_filepath=join( output_dir, 'concatenated_reference_denovo_clusters.fasta')) files_to_remove.append(output_fna_clustered) files_to_remove.append(output_fna_failures) files_to_remove.append(output_filepath_clustered_failures) if not save_intermediate_files: remove_files(files_to_remove) return app_result, output_filepath
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '30']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'assign_reads_to_otus'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'original_fasta'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'filtered_fasta'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'output_filepath'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'log_name'}, {'id': '11', 'type': 'string', 'children': [], 'value': '"assign_reads_to_otus.log"'}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'perc_id_blast'}; {'id': '14', 'type': 'float', 'children': [], 'value': '0.97'}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'global_alignment'}, {'id': '17', 'type': 'True', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}; {'id': '20', 'type': 'False', 'children': []}, {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'save_intermediate_files'}, {'id': '23', 'type': 'False', 'children': []}; {'id': '24', 'type': 'default_parameter', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'remove_usearch_logs'}; {'id': '26', 'type': 'False', 'children': []}, {'id': '27', 'type': 'default_parameter', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'working_dir'}, {'id': '29', 'type': 'None', 'children': []}; {'id': '30', 'type': 'block', 'children': ['31', '49', '57', '67', '80', '93', '103', '110']}, {'id': '31', 'type': 'if_statement', 'children': ['32', '34']}; {'id': '32', 'type': 'not_operator', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'output_filepath'}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '40']}, {'id': '37', 'type': 'pattern_list', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'output_filepath'}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'mkstemp'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '46']}, {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '45', 'type': 'string', 'children': [], 'value': "'assign_reads_to_otus'"}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'suffix'}; {'id': '48', 'type': 'string', 'children': [], 'value': "'.uc'"}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'log_filepath'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'working_dir'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'log_name'}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '60', 'type': 'dictionary', 'children': ['61', '64']}, {'id': '61', 'type': 'pair', 'children': ['62', '63']}; {'id': '62', 'type': 'string', 'children': [], 'value': "'--id'"}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'perc_id_blast'}; {'id': '64', 'type': 'pair', 'children': ['65', '66']}, {'id': '65', 'type': 'string', 'children': [], 'value': "'--global'"}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'global_alignment'}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'Usearch'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74', '77']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'WorkingDir'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'working_dir'}, {'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '83', 'type': 'dictionary', 'children': ['84', '87', '90']}; {'id': '84', 'type': 'pair', 'children': ['85', '86']}, {'id': '85', 'type': 'string', 'children': [], 'value': "'--query'"}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'original_fasta'}, {'id': '87', 'type': 'pair', 'children': ['88', '89']}; {'id': '88', 'type': 'string', 'children': [], 'value': "'--db'"}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'filtered_fasta'}; {'id': '90', 'type': 'pair', 'children': ['91', '92']}, {'id': '91', 'type': 'string', 'children': [], 'value': "'--uc'"}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'output_filepath'}, {'id': '93', 'type': 'if_statement', 'children': ['94', '96']}; {'id': '94', 'type': 'not_operator', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'remove_usearch_logs'}; {'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': 'data'}, {'id': '101', 'type': 'string', 'children': [], 'value': "'--log'"}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'log_filepath'}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'app_result'}; {'id': '106', 'type': 'call', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '110', 'type': 'return_statement', 'children': ['111']}, {'id': '111', 'type': 'expression_list', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'app_result'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'output_filepath'}
def assign_reads_to_otus(original_fasta, filtered_fasta, output_filepath=None, log_name="assign_reads_to_otus.log", perc_id_blast=0.97, global_alignment=True, HALT_EXEC=False, save_intermediate_files=False, remove_usearch_logs=False, working_dir=None): if not output_filepath: _, output_filepath = mkstemp(prefix='assign_reads_to_otus', suffix='.uc') log_filepath = join(working_dir, log_name) params = {'--id': perc_id_blast, '--global': global_alignment} app = Usearch(params, WorkingDir=working_dir, HALT_EXEC=HALT_EXEC) data = {'--query': original_fasta, '--db': filtered_fasta, '--uc': output_filepath } if not remove_usearch_logs: data['--log'] = log_filepath app_result = app(data) return app_result, output_filepath
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '32']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_by_abundance_usearch61'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'seq_path'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'output_dir'}, {'id': '7', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'rev'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'minlen'}, {'id': '13', 'type': 'integer', 'children': [], 'value': '64'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'remove_usearch_logs'}; {'id': '16', 'type': 'False', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}, {'id': '19', 'type': 'False', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'output_fna_filepath'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'output_uc_filepath'}, {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'log_name'}; {'id': '28', 'type': 'string', 'children': [], 'value': '"abundance_sorted.log"'}, {'id': '29', 'type': 'default_parameter', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'threads'}, {'id': '31', 'type': 'float', 'children': [], 'value': '1.0'}; {'id': '32', 'type': 'block', 'children': ['33', '51', '69', '77', '99', '108', '118', '131', '137']}, {'id': '33', 'type': 'if_statement', 'children': ['34', '36']}; {'id': '34', 'type': 'not_operator', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'output_fna_filepath'}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '42']}, {'id': '39', 'type': 'pattern_list', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'output_fna_filepath'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'mkstemp'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '48']}, {'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '47', 'type': 'string', 'children': [], 'value': "'abundance_sorted'"}; {'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'suffix'}; {'id': '50', 'type': 'string', 'children': [], 'value': "'.fna'"}, {'id': '51', 'type': 'if_statement', 'children': ['52', '54']}; {'id': '52', 'type': 'not_operator', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'output_uc_filepath'}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '60']}, {'id': '57', 'type': 'pattern_list', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'output_uc_filepath'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'mkstemp'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '66']}, {'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '65', 'type': 'string', 'children': [], 'value': "'abundance_sorted'"}; {'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'suffix'}; {'id': '68', 'type': 'string', 'children': [], 'value': "'.uc'"}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'log_filepath'}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '74', 'type': 'argument_list', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'log_name'}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '80', 'type': 'dictionary', 'children': ['81', '84', '87', '90', '93', '96']}, {'id': '81', 'type': 'pair', 'children': ['82', '83']}; {'id': '82', 'type': 'string', 'children': [], 'value': "'--minseqlength'"}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'minlen'}; {'id': '84', 'type': 'pair', 'children': ['85', '86']}, {'id': '85', 'type': 'string', 'children': [], 'value': "'--sizeout'"}; {'id': '86', 'type': 'True', 'children': []}, {'id': '87', 'type': 'pair', 'children': ['88', '89']}; {'id': '88', 'type': 'string', 'children': [], 'value': "'--derep_fulllength'"}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'seq_path'}; {'id': '90', 'type': 'pair', 'children': ['91', '92']}, {'id': '91', 'type': 'string', 'children': [], 'value': "'--output'"}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'output_fna_filepath'}, {'id': '93', 'type': 'pair', 'children': ['94', '95']}; {'id': '94', 'type': 'string', 'children': [], 'value': "'--uc'"}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'output_uc_filepath'}; {'id': '96', 'type': 'pair', 'children': ['97', '98']}, {'id': '97', 'type': 'string', 'children': [], 'value': "'--threads'"}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'threads'}, {'id': '99', 'type': 'if_statement', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'rev'}, {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '107']}; {'id': '104', 'type': 'subscript', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '106', 'type': 'string', 'children': [], 'value': "'--strand'"}, {'id': '107', 'type': 'string', 'children': [], 'value': "'both'"}; {'id': '108', 'type': 'if_statement', 'children': ['109', '111']}, {'id': '109', 'type': 'not_operator', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'remove_usearch_logs'}, {'id': '111', 'type': 'block', 'children': ['112']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '117']}; {'id': '114', 'type': 'subscript', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '116', 'type': 'string', 'children': [], 'value': "'--log'"}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'log_filepath'}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'Usearch61'}, {'id': '123', 'type': 'argument_list', 'children': ['124', '125', '128']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'WorkingDir'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'app_result'}; {'id': '134', 'type': 'call', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '136', 'type': 'argument_list', 'children': []}, {'id': '137', 'type': 'return_statement', 'children': ['138']}; {'id': '138', 'type': 'expression_list', 'children': ['139', '140', '141']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'output_fna_filepath'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'output_uc_filepath'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'app_result'}
def sort_by_abundance_usearch61(seq_path, output_dir='.', rev=False, minlen=64, remove_usearch_logs=False, HALT_EXEC=False, output_fna_filepath=None, output_uc_filepath=None, log_name="abundance_sorted.log", threads=1.0): if not output_fna_filepath: _, output_fna_filepath = mkstemp(prefix='abundance_sorted', suffix='.fna') if not output_uc_filepath: _, output_uc_filepath = mkstemp(prefix='abundance_sorted', suffix='.uc') log_filepath = join(output_dir, log_name) params = {'--minseqlength': minlen, '--sizeout': True, '--derep_fulllength': seq_path, '--output': output_fna_filepath, '--uc': output_uc_filepath, '--threads': threads } if rev: params['--strand'] = 'both' if not remove_usearch_logs: params['--log'] = log_filepath app = Usearch61(params, WorkingDir=output_dir, HALT_EXEC=HALT_EXEC) app_result = app() return output_fna_filepath, output_uc_filepath, app_result
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_by_length_usearch61'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'seq_path'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'output_dir'}, {'id': '7', 'type': 'string', 'children': [], 'value': '"."'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'minlen'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '64'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'remove_usearch_logs'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}; {'id': '16', 'type': 'False', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'output_fna_filepath'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'log_name'}; {'id': '22', 'type': 'string', 'children': [], 'value': '"length_sorted.log"'}, {'id': '23', 'type': 'block', 'children': ['24', '42', '50', '63', '73', '86', '92']}; {'id': '24', 'type': 'if_statement', 'children': ['25', '27']}, {'id': '25', 'type': 'not_operator', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'output_fna_filepath'}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '33']}; {'id': '30', 'type': 'pattern_list', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'output_fna_filepath'}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'mkstemp'}, {'id': '35', 'type': 'argument_list', 'children': ['36', '39']}; {'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '38', 'type': 'string', 'children': [], 'value': "'length_sorted'"}, {'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'suffix'}, {'id': '41', 'type': 'string', 'children': [], 'value': "'.fna'"}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'log_filepath'}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'output_dir'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'log_name'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '53', 'type': 'dictionary', 'children': ['54', '57', '60']}; {'id': '54', 'type': 'pair', 'children': ['55', '56']}, {'id': '55', 'type': 'string', 'children': [], 'value': "'--minseqlength'"}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'minlen'}, {'id': '57', 'type': 'pair', 'children': ['58', '59']}; {'id': '58', 'type': 'string', 'children': [], 'value': "'--sortbylength'"}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'seq_path'}; {'id': '60', 'type': 'pair', 'children': ['61', '62']}, {'id': '61', 'type': 'string', 'children': [], 'value': "'--output'"}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'output_fna_filepath'}, {'id': '63', 'type': 'if_statement', 'children': ['64', '66']}; {'id': '64', 'type': 'not_operator', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'remove_usearch_logs'}; {'id': '66', 'type': 'block', 'children': ['67']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '72']}, {'id': '69', 'type': 'subscript', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '71', 'type': 'string', 'children': [], 'value': "'--log'"}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'log_filepath'}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '76', 'type': 'call', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'Usearch61'}; {'id': '78', 'type': 'argument_list', 'children': ['79', '80', '83']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'WorkingDir'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'output_dir'}, {'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'app_result'}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '91', 'type': 'argument_list', 'children': []}; {'id': '92', 'type': 'return_statement', 'children': ['93']}, {'id': '93', 'type': 'expression_list', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'output_fna_filepath'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'app_result'}
def sort_by_length_usearch61(seq_path, output_dir=".", minlen=64, remove_usearch_logs=False, HALT_EXEC=False, output_fna_filepath=None, log_name="length_sorted.log"): if not output_fna_filepath: _, output_fna_filepath = mkstemp(prefix='length_sorted', suffix='.fna') log_filepath = join(output_dir, log_name) params = {'--minseqlength': minlen, '--sortbylength': seq_path, '--output': output_fna_filepath } if not remove_usearch_logs: params['--log'] = log_filepath app = Usearch61(params, WorkingDir=output_dir, HALT_EXEC=HALT_EXEC) app_result = app() return output_fna_filepath, app_result
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '38']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'usearch61_fast_cluster'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32', '35']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'intermediate_fasta'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'percent_id'}, {'id': '7', 'type': 'float', 'children': [], 'value': '0.97'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'minlen'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '64'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'output_dir'}, {'id': '13', 'type': 'string', 'children': [], 'value': '"."'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'remove_usearch_logs'}; {'id': '16', 'type': 'False', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'wordlength'}, {'id': '19', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'usearch61_maxrejects'}; {'id': '22', 'type': 'integer', 'children': [], 'value': '8'}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'usearch61_maxaccepts'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}; {'id': '28', 'type': 'False', 'children': []}, {'id': '29', 'type': 'default_parameter', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'output_uc_filepath'}, {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'default_parameter', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'log_name'}; {'id': '34', 'type': 'string', 'children': [], 'value': '"fast_clustered.log"'}, {'id': '35', 'type': 'default_parameter', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'threads'}, {'id': '37', 'type': 'float', 'children': [], 'value': '1.0'}; {'id': '38', 'type': 'block', 'children': ['39', '47', '78', '88', '92', '105', '111']}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'log_filepath'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'log_name'}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '50', 'type': 'dictionary', 'children': ['51', '54', '57', '60', '63', '66', '69', '72', '75']}, {'id': '51', 'type': 'pair', 'children': ['52', '53']}; {'id': '52', 'type': 'string', 'children': [], 'value': "'--minseqlength'"}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'minlen'}; {'id': '54', 'type': 'pair', 'children': ['55', '56']}, {'id': '55', 'type': 'string', 'children': [], 'value': "'--cluster_fast'"}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'intermediate_fasta'}, {'id': '57', 'type': 'pair', 'children': ['58', '59']}; {'id': '58', 'type': 'string', 'children': [], 'value': "'--id'"}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'percent_id'}; {'id': '60', 'type': 'pair', 'children': ['61', '62']}, {'id': '61', 'type': 'string', 'children': [], 'value': "'--uc'"}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'output_uc_filepath'}, {'id': '63', 'type': 'pair', 'children': ['64', '65']}; {'id': '64', 'type': 'string', 'children': [], 'value': "'--wordlength'"}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'wordlength'}; {'id': '66', 'type': 'pair', 'children': ['67', '68']}, {'id': '67', 'type': 'string', 'children': [], 'value': "'--maxrejects'"}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'usearch61_maxrejects'}, {'id': '69', 'type': 'pair', 'children': ['70', '71']}; {'id': '70', 'type': 'string', 'children': [], 'value': "'--maxaccepts'"}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'usearch61_maxaccepts'}; {'id': '72', 'type': 'pair', 'children': ['73', '74']}, {'id': '73', 'type': 'string', 'children': [], 'value': "'--usersort'"}; {'id': '74', 'type': 'True', 'children': []}, {'id': '75', 'type': 'pair', 'children': ['76', '77']}; {'id': '76', 'type': 'string', 'children': [], 'value': "'--threads'"}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'threads'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '81']}, {'id': '79', 'type': 'not_operator', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'remove_usearch_logs'}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '87']}; {'id': '84', 'type': 'subscript', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '86', 'type': 'string', 'children': [], 'value': "'--log'"}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'log_filepath'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'clusters_fp'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'output_uc_filepath'}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'Usearch61'}, {'id': '97', 'type': 'argument_list', 'children': ['98', '99', '102']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'WorkingDir'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'app_result'}; {'id': '108', 'type': 'call', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '110', 'type': 'argument_list', 'children': []}, {'id': '111', 'type': 'return_statement', 'children': ['112']}; {'id': '112', 'type': 'expression_list', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'clusters_fp'}
def usearch61_fast_cluster(intermediate_fasta, percent_id=0.97, minlen=64, output_dir=".", remove_usearch_logs=False, wordlength=8, usearch61_maxrejects=8, usearch61_maxaccepts=1, HALT_EXEC=False, output_uc_filepath=None, log_name="fast_clustered.log", threads=1.0): log_filepath = join(output_dir, log_name) params = {'--minseqlength': minlen, '--cluster_fast': intermediate_fasta, '--id': percent_id, '--uc': output_uc_filepath, '--wordlength': wordlength, '--maxrejects': usearch61_maxrejects, '--maxaccepts': usearch61_maxaccepts, '--usersort': True, '--threads': threads } if not remove_usearch_logs: params['--log'] = log_filepath clusters_fp = output_uc_filepath app = Usearch61(params, WorkingDir=output_dir, HALT_EXEC=HALT_EXEC) app_result = app() return clusters_fp, app_result
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '47']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'usearch61_smallmem_cluster'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32', '35', '38', '41', '44']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'intermediate_fasta'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'percent_id'}, {'id': '7', 'type': 'float', 'children': [], 'value': '0.97'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'minlen'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '64'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'rev'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '16', 'type': 'string', 'children': [], 'value': '"."'}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'remove_usearch_logs'}, {'id': '19', 'type': 'False', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'wordlength'}; {'id': '22', 'type': 'integer', 'children': [], 'value': '8'}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'usearch61_maxrejects'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'usearch61_maxaccepts'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '29', 'type': 'default_parameter', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'sizeorder'}, {'id': '31', 'type': 'False', 'children': []}; {'id': '32', 'type': 'default_parameter', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}; {'id': '34', 'type': 'False', 'children': []}, {'id': '35', 'type': 'default_parameter', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'output_uc_filepath'}, {'id': '37', 'type': 'None', 'children': []}; {'id': '38', 'type': 'default_parameter', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'log_name'}; {'id': '40', 'type': 'string', 'children': [], 'value': '"smallmem_clustered.log"'}, {'id': '41', 'type': 'default_parameter', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'sizeout'}, {'id': '43', 'type': 'False', 'children': []}; {'id': '44', 'type': 'default_parameter', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'consout_filepath'}; {'id': '46', 'type': 'None', 'children': []}, {'id': '47', 'type': 'block', 'children': ['48', '56', '84', '93', '103', '120', '129', '138', '142', '155', '161']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'log_filepath'}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'output_dir'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'log_name'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '59', 'type': 'dictionary', 'children': ['60', '63', '66', '69', '72', '75', '78', '81']}; {'id': '60', 'type': 'pair', 'children': ['61', '62']}, {'id': '61', 'type': 'string', 'children': [], 'value': "'--minseqlength'"}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'minlen'}, {'id': '63', 'type': 'pair', 'children': ['64', '65']}; {'id': '64', 'type': 'string', 'children': [], 'value': "'--cluster_smallmem'"}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'intermediate_fasta'}; {'id': '66', 'type': 'pair', 'children': ['67', '68']}, {'id': '67', 'type': 'string', 'children': [], 'value': "'--id'"}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'percent_id'}, {'id': '69', 'type': 'pair', 'children': ['70', '71']}; {'id': '70', 'type': 'string', 'children': [], 'value': "'--uc'"}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'output_uc_filepath'}; {'id': '72', 'type': 'pair', 'children': ['73', '74']}, {'id': '73', 'type': 'string', 'children': [], 'value': "'--wordlength'"}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'wordlength'}, {'id': '75', 'type': 'pair', 'children': ['76', '77']}; {'id': '76', 'type': 'string', 'children': [], 'value': "'--maxrejects'"}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'usearch61_maxrejects'}; {'id': '78', 'type': 'pair', 'children': ['79', '80']}, {'id': '79', 'type': 'string', 'children': [], 'value': "'--maxaccepts'"}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'usearch61_maxaccepts'}, {'id': '81', 'type': 'pair', 'children': ['82', '83']}; {'id': '82', 'type': 'string', 'children': [], 'value': "'--usersort'"}, {'id': '83', 'type': 'True', 'children': []}; {'id': '84', 'type': 'if_statement', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'sizeorder'}; {'id': '86', 'type': 'block', 'children': ['87']}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '92']}, {'id': '89', 'type': 'subscript', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '91', 'type': 'string', 'children': [], 'value': "'--sizeorder'"}; {'id': '92', 'type': 'True', 'children': []}, {'id': '93', 'type': 'if_statement', 'children': ['94', '96']}; {'id': '94', 'type': 'not_operator', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'remove_usearch_logs'}; {'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': 'params'}, {'id': '101', 'type': 'string', 'children': [], 'value': "'--log'"}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'log_filepath'}, {'id': '103', 'type': 'if_statement', 'children': ['104', '105', '112']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'rev'}, {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '111']}; {'id': '108', 'type': 'subscript', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '110', 'type': 'string', 'children': [], 'value': "'--strand'"}, {'id': '111', 'type': 'string', 'children': [], 'value': "'both'"}; {'id': '112', 'type': 'else_clause', 'children': ['113']}, {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '119']}; {'id': '116', 'type': 'subscript', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '118', 'type': 'string', 'children': [], 'value': "'--strand'"}, {'id': '119', 'type': 'string', 'children': [], 'value': "'plus'"}; {'id': '120', 'type': 'if_statement', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'sizeout'}; {'id': '122', 'type': 'block', 'children': ['123']}, {'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': 'params'}, {'id': '127', 'type': 'string', 'children': [], 'value': "'--sizeout'"}; {'id': '128', 'type': 'True', 'children': []}, {'id': '129', 'type': 'if_statement', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'consout_filepath'}, {'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': 'params'}; {'id': '136', 'type': 'string', 'children': [], 'value': "'--consout'"}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'consout_filepath'}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'clusters_fp'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'output_uc_filepath'}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'Usearch61'}, {'id': '147', 'type': 'argument_list', 'children': ['148', '149', '152']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '149', 'type': 'keyword_argument', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'WorkingDir'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'app_result'}; {'id': '158', 'type': 'call', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '160', 'type': 'argument_list', 'children': []}, {'id': '161', 'type': 'return_statement', 'children': ['162']}; {'id': '162', 'type': 'expression_list', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'clusters_fp'}
def usearch61_smallmem_cluster(intermediate_fasta, percent_id=0.97, minlen=64, rev=False, output_dir=".", remove_usearch_logs=False, wordlength=8, usearch61_maxrejects=32, usearch61_maxaccepts=1, sizeorder=False, HALT_EXEC=False, output_uc_filepath=None, log_name="smallmem_clustered.log", sizeout=False, consout_filepath=None): log_filepath = join(output_dir, log_name) params = {'--minseqlength': minlen, '--cluster_smallmem': intermediate_fasta, '--id': percent_id, '--uc': output_uc_filepath, '--wordlength': wordlength, '--maxrejects': usearch61_maxrejects, '--maxaccepts': usearch61_maxaccepts, '--usersort': True } if sizeorder: params['--sizeorder'] = True if not remove_usearch_logs: params['--log'] = log_filepath if rev: params['--strand'] = 'both' else: params['--strand'] = 'plus' if sizeout: params['--sizeout'] = True if consout_filepath: params['--consout'] = consout_filepath clusters_fp = output_uc_filepath app = Usearch61(params, WorkingDir=output_dir, HALT_EXEC=HALT_EXEC) app_result = app() return clusters_fp, app_result
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'normalize'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '7', 'type': 'block', 'children': ['8', '49']}; {'id': '8', 'type': 'for_statement', 'children': ['9', '12', '20']}, {'id': '9', 'type': 'pattern_list', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '19', 'type': 'argument_list', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21']}, {'id': '21', 'type': 'if_statement', 'children': ['22', '25']}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'in'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'block', 'children': ['26', '34', '48']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'delta'}, {'id': '29', 'type': 'binary_operator', 'children': ['30', '31'], 'value': '-'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '31', 'type': 'subscript', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '34', 'type': 'for_statement', 'children': ['35', '36', '41']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '40', 'type': 'argument_list', 'children': []}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'augmented_assignment', 'children': ['44', '47'], 'value': '+='}; {'id': '44', 'type': 'subscript', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '48', 'type': 'break_statement', 'children': []}, {'id': '49', 'type': 'return_statement', 'children': ['50']}
def normalize(self, **kwargs): for key, offset in sorted(kwargs.items()): if key in self: delta = offset - self[key] for key in self.keys(): self[key] += delta break return self
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_modifyInternal'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'keyword_separator', 'children': []}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'purge'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'done'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16', '30', '44', '202', '320']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '21']}; {'id': '18', 'type': 'pattern_list', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'sortAll'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'sortLevels'}, {'id': '21', 'type': 'boolean_operator', 'children': ['22', '27'], 'value': 'or'}; {'id': '22', 'type': 'boolean_operator', 'children': ['23', '26'], 'value': 'and'}, {'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'is'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '27', 'type': 'tuple', 'children': ['28', '29']}; {'id': '28', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '29', 'type': 'dictionary', 'children': []}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '35']}; {'id': '32', 'type': 'pattern_list', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'doneAll'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'doneLevels'}, {'id': '35', 'type': 'boolean_operator', 'children': ['36', '41'], 'value': 'or'}; {'id': '36', 'type': 'boolean_operator', 'children': ['37', '40'], 'value': 'and'}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'is'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'done'}, {'id': '39', 'type': 'None', 'children': []}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'done'}, {'id': '41', 'type': 'tuple', 'children': ['42', '43']}; {'id': '42', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '43', 'type': 'dictionary', 'children': []}; {'id': '44', 'type': 'function_definition', 'children': ['45', '46', '49']}, {'id': '45', 'type': 'function_name', 'children': [], 'value': '_mark'}; {'id': '46', 'type': 'parameters', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '49', 'type': 'block', 'children': ['50', '61', '150', '177', '189', '200']}; {'id': '50', 'type': 'if_statement', 'children': ['51', '54']}, {'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'is'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'done'}, {'id': '53', 'type': 'None', 'children': []}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'return_statement', 'children': ['56']}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '58', 'type': 'slice', 'children': ['59', '60']}, {'id': '59', 'type': 'colon', 'children': []}; {'id': '60', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '61', 'type': 'function_definition', 'children': ['62', '63', '67']}; {'id': '62', 'type': 'function_name', 'children': [], 'value': '_mark_'}, {'id': '63', 'type': 'parameters', 'children': ['64', '65', '66']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'regexp'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'du'}, {'id': '67', 'type': 'block', 'children': ['68', '79', '123']}; {'id': '68', 'type': 'if_statement', 'children': ['69', '72']}, {'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': 'is'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'du'}, {'id': '71', 'type': 'None', 'children': []}; {'id': '72', 'type': 'block', 'children': ['73']}, {'id': '73', 'type': 'return_statement', 'children': ['74']}; {'id': '74', 'type': 'subscript', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '76', 'type': 'slice', 'children': ['77', '78']}, {'id': '77', 'type': 'colon', 'children': []}; {'id': '78', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '79', 'type': 'if_statement', 'children': ['80', '83']}; {'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': 'is'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '82', 'type': 'None', 'children': []}, {'id': '83', 'type': 'block', 'children': ['84', '117']}; {'id': '84', 'type': 'for_statement', 'children': ['85', '86', '91']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'v_'}; {'id': '86', 'type': 'subscript', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '88', 'type': 'slice', 'children': ['89', '90']}, {'id': '89', 'type': 'colon', 'children': []}; {'id': '90', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'if_statement', 'children': ['93', '107']}, {'id': '93', 'type': 'boolean_operator', 'children': ['94', '97'], 'value': 'or'}; {'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': 'is'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'regexp'}; {'id': '96', 'type': 'None', 'children': []}, {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '101', 'type': 'argument_list', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'regexp'}, {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'v_'}, {'id': '107', 'type': 'block', 'children': ['108']}; {'id': '108', 'type': 'return_statement', 'children': ['109']}, {'id': '109', 'type': 'binary_operator', 'children': ['110', '115'], 'value': '+'}; {'id': '110', 'type': 'subscript', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '112', 'type': 'slice', 'children': ['113', '114']}, {'id': '113', 'type': 'colon', 'children': []}; {'id': '114', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '115', 'type': 'list', 'children': ['116'], 'value': '[du]'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'du'}, {'id': '117', 'type': 'return_statement', 'children': ['118']}; {'id': '118', 'type': 'subscript', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '120', 'type': 'slice', 'children': ['121', '122']}, {'id': '121', 'type': 'colon', 'children': []}; {'id': '122', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '123', 'type': 'if_statement', 'children': ['124', '140']}; {'id': '124', 'type': 'boolean_operator', 'children': ['125', '128'], 'value': 'or'}, {'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': 'is'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'regexp'}, {'id': '127', 'type': 'None', 'children': []}; {'id': '128', 'type': 'call', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '132', 'type': 'argument_list', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'regexp'}; {'id': '134', 'type': 'call', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}, {'id': '137', 'type': 'subscript', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '140', 'type': 'block', 'children': ['141']}, {'id': '141', 'type': 'return_statement', 'children': ['142']}; {'id': '142', 'type': 'binary_operator', 'children': ['143', '148'], 'value': '+'}, {'id': '143', 'type': 'subscript', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '145', 'type': 'slice', 'children': ['146', '147']}; {'id': '146', 'type': 'colon', 'children': []}, {'id': '147', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '148', 'type': 'list', 'children': ['149'], 'value': '[du]'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'du'}; {'id': '150', 'type': 'try_statement', 'children': ['151', '173']}, {'id': '151', 'type': 'block', 'children': ['152', '166']}; {'id': '152', 'type': 'for_statement', 'children': ['153', '154', '157']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'doneLevel'}; {'id': '154', 'type': 'subscript', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'doneLevels'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '157', 'type': 'block', 'children': ['158']}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'assignment', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': '_mark_'}, {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'list_splat', 'children': ['165']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'doneLevel'}; {'id': '166', 'type': 'if_statement', 'children': ['167', '170']}, {'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': 'is'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '169', 'type': 'None', 'children': []}; {'id': '170', 'type': 'block', 'children': ['171']}, {'id': '171', 'type': 'return_statement', 'children': ['172']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '173', 'type': 'except_clause', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'KeyError'}, {'id': '175', 'type': 'block', 'children': ['176']}; {'id': '176', 'type': 'pass_statement', 'children': []}, {'id': '177', 'type': 'for_statement', 'children': ['178', '179', '180']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'doneAll_'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'doneAll'}; {'id': '180', 'type': 'block', 'children': ['181']}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '184', 'type': 'call', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': '_mark_'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}, {'id': '187', 'type': 'list_splat', 'children': ['188']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'doneAll_'}, {'id': '189', 'type': 'if_statement', 'children': ['190', '193']}; {'id': '190', 'type': 'comparison_operator', 'children': ['191', '192'], 'value': 'is'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '192', 'type': 'None', 'children': []}, {'id': '193', 'type': 'block', 'children': ['194']}; {'id': '194', 'type': 'return_statement', 'children': ['195']}, {'id': '195', 'type': 'subscript', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '197', 'type': 'slice', 'children': ['198', '199']}; {'id': '198', 'type': 'colon', 'children': []}, {'id': '199', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '200', 'type': 'return_statement', 'children': ['201']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '202', 'type': 'function_definition', 'children': ['203', '204', '207']}, {'id': '203', 'type': 'function_name', 'children': [], 'value': '_modify'}; {'id': '204', 'type': 'parameters', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'submodel'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '207', 'type': 'block', 'children': ['208', '214', '273', '292', '318']}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}, {'id': '209', 'type': 'assignment', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': '_new'}, {'id': '211', 'type': 'call', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '213', 'type': 'argument_list', 'children': []}; {'id': '214', 'type': 'for_statement', 'children': ['215', '216', '217']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'submodel'}, {'id': '217', 'type': 'block', 'children': ['218']}; {'id': '218', 'type': 'if_statement', 'children': ['219', '220', '249']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'purge'}; {'id': '220', 'type': 'block', 'children': ['221']}, {'id': '221', 'type': 'if_statement', 'children': ['222', '226']}; {'id': '222', 'type': 'not_operator', 'children': ['223']}, {'id': '223', 'type': 'subscript', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '225', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '226', 'type': 'block', 'children': ['227']}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'call', 'children': ['229', '232']}, {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': '_new'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '232', 'type': 'argument_list', 'children': ['233']}, {'id': '233', 'type': 'binary_operator', 'children': ['234', '239'], 'value': '+'}; {'id': '234', 'type': 'call', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': '_mark'}; {'id': '236', 'type': 'argument_list', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '239', 'type': 'list', 'children': ['240'], 'value': '[_modify(v[4], i + 1)]'}; {'id': '240', 'type': 'call', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': '_modify'}; {'id': '242', 'type': 'argument_list', 'children': ['243', '246']}, {'id': '243', 'type': 'subscript', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '245', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '246', 'type': 'binary_operator', 'children': ['247', '248'], 'value': '+'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '248', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '249', 'type': 'else_clause', 'children': ['250']}; {'id': '250', 'type': 'block', 'children': ['251']}, {'id': '251', 'type': 'expression_statement', 'children': ['252']}; {'id': '252', 'type': 'call', 'children': ['253', '256']}, {'id': '253', 'type': 'attribute', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': '_new'}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '256', 'type': 'argument_list', 'children': ['257']}, {'id': '257', 'type': 'binary_operator', 'children': ['258', '263'], 'value': '+'}; {'id': '258', 'type': 'call', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': '_mark'}; {'id': '260', 'type': 'argument_list', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '263', 'type': 'list', 'children': ['264'], 'value': '[_modify(v[4], i + 1)]'}; {'id': '264', 'type': 'call', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': '_modify'}; {'id': '266', 'type': 'argument_list', 'children': ['267', '270']}, {'id': '267', 'type': 'subscript', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '269', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '270', 'type': 'binary_operator', 'children': ['271', '272'], 'value': '+'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '272', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '273', 'type': 'expression_statement', 'children': ['274']}; {'id': '274', 'type': 'assignment', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'levels'}; {'id': '276', 'type': 'boolean_operator', 'children': ['277', '283'], 'value': 'or'}, {'id': '277', 'type': 'call', 'children': ['278', '281']}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'sortLevels'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '281', 'type': 'argument_list', 'children': ['282']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '283', 'type': 'call', 'children': ['284', '287']}; {'id': '284', 'type': 'attribute', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'sortLevels'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '287', 'type': 'argument_list', 'children': ['288']}; {'id': '288', 'type': 'call', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '290', 'type': 'argument_list', 'children': ['291']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '292', 'type': 'for_statement', 'children': ['293', '296', '299']}, {'id': '293', 'type': 'pattern_list', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '296', 'type': 'boolean_operator', 'children': ['297', '298'], 'value': 'or'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'levels'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'sortAll'}, {'id': '299', 'type': 'block', 'children': ['300']}; {'id': '300', 'type': 'expression_statement', 'children': ['301']}, {'id': '301', 'type': 'assignment', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': '_new'}, {'id': '303', 'type': 'call', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '305', 'type': 'argument_list', 'children': ['306', '307', '315']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': '_new'}, {'id': '307', 'type': 'keyword_argument', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '309', 'type': 'lambda', 'children': ['310', '312']}; {'id': '310', 'type': 'lambda_parameters', 'children': ['311']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '312', 'type': 'subscript', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '315', 'type': 'keyword_argument', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '318', 'type': 'return_statement', 'children': ['319']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': '_new'}; {'id': '320', 'type': 'return_statement', 'children': ['321']}, {'id': '321', 'type': 'call', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': '_modify'}, {'id': '323', 'type': 'argument_list', 'children': ['324', '327']}; {'id': '324', 'type': 'attribute', 'children': ['325', '326']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '327', 'type': 'integer', 'children': [], 'value': '1'}
def _modifyInternal(self, *, sort=None, purge=False, done=None): sortAll, sortLevels = sort is not None and sort or ([], {}) doneAll, doneLevels = done is not None and done or ([], {}) def _mark(v, i): if done is None: return v[:4] def _mark_(index, regexp, du): if du is None: return v[:4] if index is None: for v_ in v[:3]: if regexp is None or re.match(regexp, str(v_)): return v[:3] + [du] return v[:4] if regexp is None or re.match(regexp, str(v[index])): return v[:3] + [du] try: for doneLevel in doneLevels[i]: result = _mark_(*doneLevel) if result is not None: return result except KeyError: pass for doneAll_ in doneAll: result = _mark_(*doneAll_) if result is None: return v[:4] return result def _modify(submodel, i): _new = list() for v in submodel: if purge: if not v[3]: _new.append(_mark(v, i) + [_modify(v[4], i + 1)]) else: _new.append(_mark(v, i) + [_modify(v[4], i + 1)]) levels = sortLevels.get(i) or sortLevels.get(str(i)) for index, reverse in levels or sortAll: _new = sorted(_new, key=lambda e: e[index], reverse=reverse) return _new return _modify(self.data, 1)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_getPattern'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'ipattern'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'done'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '17', '42', '51', '72', '127', '133', '139', '365']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '14']}, {'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'is'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'ipattern'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'return_statement', 'children': ['16']}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'if_statement', 'children': ['18', '21']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'is'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'ipattern'}; {'id': '20', 'type': 'True', 'children': []}, {'id': '21', 'type': 'block', 'children': ['22', '35']}; {'id': '22', 'type': 'if_statement', 'children': ['23', '26']}, {'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'is'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'done'}, {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'return_statement', 'children': ['28']}; {'id': '28', 'type': 'tuple', 'children': ['29', '34']}, {'id': '29', 'type': 'list', 'children': ['30'], 'value': '[(None, None, done)]'}; {'id': '30', 'type': 'tuple', 'children': ['31', '32', '33']}, {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'None', 'children': []}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'done'}; {'id': '34', 'type': 'dictionary', 'children': []}, {'id': '35', 'type': 'return_statement', 'children': ['36']}; {'id': '36', 'type': 'tuple', 'children': ['37', '41']}, {'id': '37', 'type': 'list', 'children': ['38'], 'value': '[(0, False)]'}; {'id': '38', 'type': 'tuple', 'children': ['39', '40']}, {'id': '39', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '40', 'type': 'False', 'children': []}, {'id': '41', 'type': 'dictionary', 'children': []}; {'id': '42', 'type': 'function_definition', 'children': ['43', '44', '46']}, {'id': '43', 'type': 'function_name', 'children': [], 'value': '_getReverse'}; {'id': '44', 'type': 'parameters', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'pm'}; {'id': '46', 'type': 'block', 'children': ['47']}, {'id': '47', 'type': 'return_statement', 'children': ['48']}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': '=='}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'pm'}; {'id': '50', 'type': 'string', 'children': [], 'value': "'-'"}, {'id': '51', 'type': 'function_definition', 'children': ['52', '53', '55']}; {'id': '52', 'type': 'function_name', 'children': [], 'value': '_getIndex'}, {'id': '53', 'type': 'parameters', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'try_statement', 'children': ['57', '63']}, {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'return_statement', 'children': ['59']}, {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '63', 'type': 'except_clause', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'raise_statement', 'children': ['67']}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'InvalidPatternError'}, {'id': '69', 'type': 'argument_list', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '71', 'type': 'string', 'children': [], 'value': '"Invalid level number"'}; {'id': '72', 'type': 'function_definition', 'children': ['73', '74', '76']}, {'id': '73', 'type': 'function_name', 'children': [], 'value': '_getDone'}; {'id': '74', 'type': 'parameters', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '76', 'type': 'block', 'children': ['77', '86', '120']}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '80', 'type': 'call', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'string', 'children': [], 'value': "'='"}; {'id': '86', 'type': 'if_statement', 'children': ['87', '93']}, {'id': '87', 'type': 'comparison_operator', 'children': ['88', '92'], 'value': '=='}; {'id': '88', 'type': 'call', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '92', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'try_statement', 'children': ['95', '109']}, {'id': '95', 'type': 'block', 'children': ['96']}; {'id': '96', 'type': 'return_statement', 'children': ['97']}, {'id': '97', 'type': 'tuple', 'children': ['98', '105', '108']}; {'id': '98', 'type': 'subscript', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'Model'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'indexes'}; {'id': '102', 'type': 'subscript', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '104', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '105', 'type': 'subscript', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '107', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'done'}, {'id': '109', 'type': 'except_clause', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'KeyError'}, {'id': '111', 'type': 'block', 'children': ['112']}; {'id': '112', 'type': 'raise_statement', 'children': ['113']}, {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'InvalidPatternError'}, {'id': '115', 'type': 'argument_list', 'children': ['116', '119']}; {'id': '116', 'type': 'subscript', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '118', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '119', 'type': 'string', 'children': [], 'value': "'Invalid field name'"}; {'id': '120', 'type': 'return_statement', 'children': ['121']}, {'id': '121', 'type': 'tuple', 'children': ['122', '123', '126']}; {'id': '122', 'type': 'None', 'children': []}, {'id': '123', 'type': 'subscript', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '125', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'done'}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'ipattern1'}; {'id': '130', 'type': 'call', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '132', 'type': 'argument_list', 'children': []}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'ipattern2'}; {'id': '136', 'type': 'call', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '138', 'type': 'argument_list', 'children': []}, {'id': '139', 'type': 'for_statement', 'children': ['140', '141', '147']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'ipattern'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'string', 'children': [], 'value': "','"}, {'id': '147', 'type': 'block', 'children': ['148', '169', '178', '352']}; {'id': '148', 'type': 'if_statement', 'children': ['149', '152', '157']}, {'id': '149', 'type': 'comparison_operator', 'children': ['150', '151'], 'value': 'is'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'done'}, {'id': '151', 'type': 'None', 'children': []}; {'id': '152', 'type': 'block', 'children': ['153']}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'done'}, {'id': '157', 'type': 'else_clause', 'children': ['158']}; {'id': '158', 'type': 'block', 'children': ['159']}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '162', 'type': 'call', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': '_getReverse'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'subscript', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '167', 'type': 'unary_operator', 'children': ['168'], 'value': '-'}; {'id': '168', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '172', 'type': 'call', 'children': ['173', '176']}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '176', 'type': 'argument_list', 'children': ['177']}, {'id': '177', 'type': 'string', 'children': [], 'value': "':'"}; {'id': '178', 'type': 'if_statement', 'children': ['179', '185', '276', '344']}, {'id': '179', 'type': 'comparison_operator', 'children': ['180', '184'], 'value': '=='}; {'id': '180', 'type': 'call', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '184', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '185', 'type': 'block', 'children': ['186', '204', '215', '270']}; {'id': '186', 'type': 'if_statement', 'children': ['187', '190']}, {'id': '187', 'type': 'comparison_operator', 'children': ['188', '189'], 'value': 'is'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'done'}, {'id': '189', 'type': 'None', 'children': []}; {'id': '190', 'type': 'block', 'children': ['191', '203']}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'call', 'children': ['193', '196']}, {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'ipattern1'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '196', 'type': 'argument_list', 'children': ['197']}, {'id': '197', 'type': 'call', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': '_getDone'}, {'id': '199', 'type': 'argument_list', 'children': ['200']}; {'id': '200', 'type': 'subscript', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '202', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '203', 'type': 'continue_statement', 'children': []}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}, {'id': '205', 'type': 'assignment', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'ko'}, {'id': '207', 'type': 'subscript', 'children': ['208', '211']}; {'id': '208', 'type': 'subscript', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '210', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '211', 'type': 'slice', 'children': ['212', '213']}; {'id': '212', 'type': 'colon', 'children': []}, {'id': '213', 'type': 'unary_operator', 'children': ['214'], 'value': '-'}; {'id': '214', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '215', 'type': 'try_statement', 'children': ['216', '241', '258']}; {'id': '216', 'type': 'block', 'children': ['217']}, {'id': '217', 'type': 'if_statement', 'children': ['218', '226', '231']}; {'id': '218', 'type': 'comparison_operator', 'children': ['219', '225'], 'value': '=='}, {'id': '219', 'type': 'call', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'subscript', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '224', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '225', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'k'}; {'id': '230', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '231', 'type': 'else_clause', 'children': ['232']}; {'id': '232', 'type': 'block', 'children': ['233']}, {'id': '233', 'type': 'expression_statement', 'children': ['234']}; {'id': '234', 'type': 'assignment', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '236', 'type': 'subscript', 'children': ['237', '240']}, {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'Model'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'indexes'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'ko'}, {'id': '241', 'type': 'except_clause', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'KeyError'}, {'id': '243', 'type': 'block', 'children': ['244']}; {'id': '244', 'type': 'expression_statement', 'children': ['245']}, {'id': '245', 'type': 'assignment', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '247', 'type': 'call', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': '_getIndex'}, {'id': '249', 'type': 'argument_list', 'children': ['250']}; {'id': '250', 'type': 'subscript', 'children': ['251', '254']}, {'id': '251', 'type': 'subscript', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '253', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '254', 'type': 'slice', 'children': ['255', '256']}, {'id': '255', 'type': 'colon', 'children': []}; {'id': '256', 'type': 'unary_operator', 'children': ['257'], 'value': '-'}, {'id': '257', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '258', 'type': 'else_clause', 'children': ['259']}, {'id': '259', 'type': 'block', 'children': ['260', '269']}; {'id': '260', 'type': 'expression_statement', 'children': ['261']}, {'id': '261', 'type': 'call', 'children': ['262', '265']}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'ipattern1'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '265', 'type': 'argument_list', 'children': ['266']}; {'id': '266', 'type': 'tuple', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '269', 'type': 'continue_statement', 'children': []}; {'id': '270', 'type': 'expression_statement', 'children': ['271']}, {'id': '271', 'type': 'assignment', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '273', 'type': 'tuple', 'children': ['274', '275']}; {'id': '274', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '276', 'type': 'elif_clause', 'children': ['277', '283']}, {'id': '277', 'type': 'comparison_operator', 'children': ['278', '282'], 'value': '=='}; {'id': '278', 'type': 'call', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '280', 'type': 'argument_list', 'children': ['281']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '282', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '283', 'type': 'block', 'children': ['284']}; {'id': '284', 'type': 'try_statement', 'children': ['285', '328']}, {'id': '285', 'type': 'block', 'children': ['286', '319']}; {'id': '286', 'type': 'if_statement', 'children': ['287', '290', '300']}, {'id': '287', 'type': 'comparison_operator', 'children': ['288', '289'], 'value': 'is'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'done'}, {'id': '289', 'type': 'None', 'children': []}; {'id': '290', 'type': 'block', 'children': ['291']}, {'id': '291', 'type': 'expression_statement', 'children': ['292']}; {'id': '292', 'type': 'assignment', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '294', 'type': 'call', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': '_getDone'}; {'id': '296', 'type': 'argument_list', 'children': ['297']}, {'id': '297', 'type': 'subscript', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '299', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '300', 'type': 'else_clause', 'children': ['301']}, {'id': '301', 'type': 'block', 'children': ['302']}; {'id': '302', 'type': 'expression_statement', 'children': ['303']}, {'id': '303', 'type': 'assignment', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '305', 'type': 'tuple', 'children': ['306', '318']}; {'id': '306', 'type': 'subscript', 'children': ['307', '310']}, {'id': '307', 'type': 'attribute', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'Model'}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'indexes'}; {'id': '310', 'type': 'subscript', 'children': ['311', '314']}, {'id': '311', 'type': 'subscript', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '313', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '314', 'type': 'slice', 'children': ['315', '316']}, {'id': '315', 'type': 'colon', 'children': []}; {'id': '316', 'type': 'unary_operator', 'children': ['317'], 'value': '-'}, {'id': '317', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '319', 'type': 'expression_statement', 'children': ['320']}; {'id': '320', 'type': 'assignment', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '322', 'type': 'call', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': '_getIndex'}; {'id': '324', 'type': 'argument_list', 'children': ['325']}, {'id': '325', 'type': 'subscript', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '327', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '328', 'type': 'except_clause', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '330', 'type': 'block', 'children': ['331']}, {'id': '331', 'type': 'raise_statement', 'children': ['332']}; {'id': '332', 'type': 'call', 'children': ['333', '334']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'InvalidPatternError'}; {'id': '334', 'type': 'argument_list', 'children': ['335', '343']}, {'id': '335', 'type': 'subscript', 'children': ['336', '339']}; {'id': '336', 'type': 'subscript', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '338', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '339', 'type': 'slice', 'children': ['340', '341']}; {'id': '340', 'type': 'colon', 'children': []}, {'id': '341', 'type': 'unary_operator', 'children': ['342'], 'value': '-'}; {'id': '342', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '343', 'type': 'string', 'children': [], 'value': "'Invalid field name'"}; {'id': '344', 'type': 'else_clause', 'children': ['345']}, {'id': '345', 'type': 'block', 'children': ['346']}; {'id': '346', 'type': 'raise_statement', 'children': ['347']}, {'id': '347', 'type': 'call', 'children': ['348', '349']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'InvalidPatternError'}, {'id': '349', 'type': 'argument_list', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '351', 'type': 'string', 'children': [], 'value': "'Unrecognized token in'"}; {'id': '352', 'type': 'expression_statement', 'children': ['353']}, {'id': '353', 'type': 'call', 'children': ['354', '363']}; {'id': '354', 'type': 'attribute', 'children': ['355', '362']}, {'id': '355', 'type': 'call', 'children': ['356', '359']}; {'id': '356', 'type': 'attribute', 'children': ['357', '358']}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'ipattern2'}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'setdefault'}, {'id': '359', 'type': 'argument_list', 'children': ['360', '361']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '361', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '363', 'type': 'argument_list', 'children': ['364']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '365', 'type': 'return_statement', 'children': ['366']}; {'id': '366', 'type': 'tuple', 'children': ['367', '368']}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'ipattern1'}
def _getPattern(self, ipattern, done=None): if ipattern is None: return None if ipattern is True: if done is not None: return ([(None, None, done)], {}) return ([(0, False)], {}) def _getReverse(pm): return pm == '-' def _getIndex(k): try: return int(k) except ValueError: raise InvalidPatternError(k, "Invalid level number") def _getDone(p): v = p.split('=') if len(v) == 2: try: return (Model.indexes[v[0]], v[1], done) except KeyError: raise InvalidPatternError(v[0], 'Invalid field name') return (None, v[0], done) ipattern1 = list() ipattern2 = dict() for s in ipattern.split(','): if done is not None: v = done else: v = _getReverse(s[-1]) k = s.split(':') if len(k) == 1: if done is not None: ipattern1.append(_getDone(k[0])) continue ko = k[0][:-1] try: if len(k[0]) == 1: k = 0 else: k = Model.indexes[ko] except KeyError: k = _getIndex(k[0][:-1]) else: ipattern1.append((k, v)) continue v = (0, v) elif len(k) == 2: try: if done is not None: v = _getDone(k[1]) else: v = (Model.indexes[k[1][:-1]], v) k = _getIndex(k[0]) except KeyError: raise InvalidPatternError(k[1][:-1], 'Invalid field name') else: raise InvalidPatternError(s, 'Unrecognized token in') ipattern2.setdefault(k, []).append(v) return (ipattern1, ipattern2)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'view'}, {'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': 'sort'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'purge'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'done'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'undone'}; {'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': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'View'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '51']}; {'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': 'model'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'modify'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '39', '42']}, {'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': '_getPattern'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'purge'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'purge'}; {'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'done'}; {'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': '_getDone'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'done'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'undone'}, {'id': '51', 'type': 'dictionary_splat', 'children': ['52']}
def view(self, sort=None, purge=False, done=None, undone=None, **kwargs): View(self.model.modify( sort=self._getPattern(sort), purge=purge, done=self._getDone(done, undone) ), **kwargs)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'modify'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'purge'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'done'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'undone'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '25']}; {'id': '20', 'type': 'attribute', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'modifyInPlace'}, {'id': '25', 'type': 'argument_list', 'children': ['26', '34', '37']}; {'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': '_getPattern'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'purge'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'purge'}, {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'done'}, {'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': '_getDone'}, {'id': '43', 'type': 'argument_list', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'done'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'undone'}
def modify(self, sort=None, purge=False, done=None, undone=None): self.model.modifyInPlace( sort=self._getPattern(sort), purge=purge, done=self._getDone(done, undone) )
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'inorder'}, {'id': '3', 'type': 'parameters', 'children': ['4', '6']}; {'id': '4', 'type': 'list_splat_pattern', 'children': ['5']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'iterables'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '8', 'type': 'block', 'children': ['9', '19', '32', '48', '52', '89', '94', '107', '113', '175', '185', '188']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}, {'id': '17', 'type': 'string', 'children': [], 'value': '"reverse"'}; {'id': '18', 'type': 'False', 'children': []}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'keyfunc'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28']}, {'id': '27', 'type': 'string', 'children': [], 'value': '"key"'}; {'id': '28', 'type': 'lambda', 'children': ['29', '31']}, {'id': '29', 'type': 'lambda_parameters', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '32', 'type': 'if_statement', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'raise_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'binary_operator', 'children': ['40', '41'], 'value': '%'}; {'id': '40', 'type': 'string', 'children': [], 'value': '"invalid keyword argument \'%s\'"'}, {'id': '41', 'type': 'subscript', 'children': ['42', '47']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '46', 'type': 'argument_list', 'children': []}, {'id': '47', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'nextvals'}, {'id': '51', 'type': 'dictionary', 'children': []}; {'id': '52', 'type': 'for_statement', 'children': ['53', '54', '55']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'iterable'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'iterables'}, {'id': '55', 'type': 'block', 'children': ['56', '65']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'next'}, {'id': '59', 'type': 'attribute', 'children': ['60', '64']}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'iter'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'iterable'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'next'}, {'id': '65', 'type': 'try_statement', 'children': ['66', '85']}; {'id': '66', 'type': 'block', 'children': ['67', '73']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'nextval'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '72', 'type': 'argument_list', 'children': []}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '78']}, {'id': '75', 'type': 'subscript', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'nextvals'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '78', 'type': 'expression_list', 'children': ['79', '83', '84']}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'keyfunc'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'nextval'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'nextval'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'next'}, {'id': '85', 'type': 'except_clause', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'StopIteration'}, {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'pass_statement', 'children': []}, {'id': '89', 'type': 'if_statement', 'children': ['90', '92']}; {'id': '90', 'type': 'not_operator', 'children': ['91']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'nextvals'}; {'id': '92', 'type': 'block', 'children': ['93']}, {'id': '93', 'type': 'return_statement', 'children': []}; {'id': '94', 'type': 'if_statement', 'children': ['95', '96', '101']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'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': 'select'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '101', 'type': 'else_clause', 'children': ['102']}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'select'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'nextvals'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'itervalues'}, {'id': '113', 'type': 'if_statement', 'children': ['114', '120']}; {'id': '114', 'type': 'comparison_operator', 'children': ['115', '119'], 'value': '>'}, {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'nextvals'}, {'id': '119', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '120', 'type': 'block', 'children': ['121']}, {'id': '121', 'type': 'while_statement', 'children': ['122', '123']}; {'id': '122', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '123', 'type': 'block', 'children': ['124', '136', '139']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '130']}; {'id': '126', 'type': 'pattern_list', 'children': ['127', '128', '129']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '130', 'type': 'call', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'select'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '135', 'type': 'argument_list', 'children': []}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'yield', 'children': ['138']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '139', 'type': 'try_statement', 'children': ['140', '159']}; {'id': '140', 'type': 'block', 'children': ['141', '147']}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'nextval'}; {'id': '144', 'type': 'call', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '146', 'type': 'argument_list', 'children': []}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '152']}, {'id': '149', 'type': 'subscript', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'nextvals'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '152', 'type': 'expression_list', 'children': ['153', '157', '158']}, {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'keyfunc'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'nextval'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'nextval'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'next'}, {'id': '159', 'type': 'except_clause', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'StopIteration'}, {'id': '161', 'type': 'block', 'children': ['162', '166']}; {'id': '162', 'type': 'delete_statement', 'children': ['163']}, {'id': '163', 'type': 'subscript', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'nextvals'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '166', 'type': 'if_statement', 'children': ['167', '173']}, {'id': '167', 'type': 'comparison_operator', 'children': ['168', '172'], 'value': '<'}; {'id': '168', 'type': 'call', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'nextvals'}; {'id': '172', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '173', 'type': 'block', 'children': ['174']}; {'id': '174', 'type': 'break_statement', 'children': []}, {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'assignment', 'children': ['177', '182']}, {'id': '177', 'type': 'pattern_list', 'children': ['178']}; {'id': '178', 'type': 'tuple_pattern', 'children': ['179', '180', '181']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '182', 'type': 'call', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '184', 'type': 'argument_list', 'children': []}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'yield', 'children': ['187']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '188', 'type': 'while_statement', 'children': ['189', '190']}, {'id': '189', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '190', 'type': 'block', 'children': ['191']}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'yield', 'children': ['193']}, {'id': '193', 'type': 'call', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'next'}, {'id': '195', 'type': 'argument_list', 'children': []}
def inorder(*iterables, **kwargs): reverse = kwargs.pop("reverse", False) keyfunc = kwargs.pop("key", lambda x: x) if kwargs: raise TypeError("invalid keyword argument '%s'" % kwargs.keys()[0]) nextvals = {} for iterable in iterables: next = iter(iterable).next try: nextval = next() nextvals[next] = keyfunc(nextval), nextval, next except StopIteration: pass if not nextvals: return if reverse: select = max else: select = min values = nextvals.itervalues if len(nextvals) > 1: while 1: _, val, next = select(values()) yield val try: nextval = next() nextvals[next] = keyfunc(nextval), nextval, next except StopIteration: del nextvals[next] if len(nextvals) < 2: break (_, val, next), = values() yield val while 1: yield next()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_tag'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '7', 'type': 'block', 'children': ['8', '20', '24', '46']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'bisect_left'}, {'id': '13', 'type': 'argument_list', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'tags'}, {'id': '17', 'type': 'tuple', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'contains'}, {'id': '23', 'type': 'False', 'children': []}; {'id': '24', 'type': 'if_statement', 'children': ['25', '33']}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': '<'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'tags'}, {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'contains'}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '43'], 'value': '=='}; {'id': '38', 'type': 'subscript', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'tags'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '43', 'type': 'tuple', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '46', 'type': 'if_statement', 'children': ['47', '49']}, {'id': '47', 'type': 'not_operator', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'contains'}, {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'call', 'children': ['52', '57']}; {'id': '52', 'type': 'attribute', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'tags'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'insert'}, {'id': '57', 'type': 'argument_list', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '59', 'type': 'tuple', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'value'}
def add_tag(self, tag, value): index = bisect_left(self.tags, (tag, value)) contains = False if index < len(self.tags): contains = self.tags[index] == (tag, value) if not contains: self.tags.insert(index, (tag, value))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '27']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'external'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '14', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'alpha'}, {'id': '23', 'type': 'False', 'children': []}; {'id': '24', 'type': 'default_parameter', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'store_as'}; {'id': '26', 'type': 'None', 'children': []}, {'id': '27', 'type': 'block', 'children': ['28', '49', '55', '64', '92', '118', '128', '140', '149']}; {'id': '28', 'type': 'if_statement', 'children': ['29', '38']}, {'id': '29', 'type': 'boolean_operator', 'children': ['30', '31'], 'value': 'and'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'not'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '33', 'type': 'list', 'children': ['34', '35', '36', '37'], 'value': "[b'ASC', b'DESC', 'ASC', 'DESC']"}; {'id': '34', 'type': 'string', 'children': [], 'value': "b'ASC'"}, {'id': '35', 'type': 'string', 'children': [], 'value': "b'DESC'"}; {'id': '36', 'type': 'string', 'children': [], 'value': "'ASC'"}, {'id': '37', 'type': 'string', 'children': [], 'value': "'DESC'"}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'raise_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'string', 'children': [], 'value': '\'invalid sort order "{}"\''}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '52', 'type': 'list', 'children': ['53', '54'], 'value': "[b'SORT', key]"}, {'id': '53', 'type': 'string', 'children': [], 'value': "b'SORT'"}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '55', 'type': 'if_statement', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'by'}, {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'augmented_assignment', 'children': ['60', '61'], 'value': '+='}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'command'}, {'id': '61', 'type': 'list', 'children': ['62', '63'], 'value': "[b'BY', by]"}; {'id': '62', 'type': 'string', 'children': [], 'value': "b'BY'"}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '64', 'type': 'if_statement', 'children': ['65', '72', '83']}, {'id': '65', 'type': 'boolean_operator', 'children': ['66', '67'], 'value': 'and'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'external'}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '69', 'type': 'argument_list', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'external'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '72', 'type': 'block', 'children': ['73']}, {'id': '73', 'type': 'for_statement', 'children': ['74', '75', '76']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'external'}; {'id': '76', 'type': 'block', 'children': ['77']}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'augmented_assignment', 'children': ['79', '80'], 'value': '+='}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '80', 'type': 'list', 'children': ['81', '82'], 'value': "[b'GET', entry]"}, {'id': '81', 'type': 'string', 'children': [], 'value': "b'GET'"}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '83', 'type': 'elif_clause', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'external'}, {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'augmented_assignment', 'children': ['88', '89'], 'value': '+='}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'command'}, {'id': '89', 'type': 'list', 'children': ['90', '91'], 'value': "[b'GET', external]"}; {'id': '90', 'type': 'string', 'children': [], 'value': "b'GET'"}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'external'}; {'id': '92', 'type': 'if_statement', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '94', 'type': 'block', 'children': ['95']}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'augmented_assignment', 'children': ['97', '98'], 'value': '+='}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '98', 'type': 'list', 'children': ['99', '100', '109'], 'value': "[\n b'LIMIT',\n ascii(offset).encode('utf-8'),\n ascii(limit).encode('utf-8')\n ]"}, {'id': '99', 'type': 'string', 'children': [], 'value': "b'LIMIT'"}; {'id': '100', 'type': 'call', 'children': ['101', '107']}, {'id': '101', 'type': 'attribute', 'children': ['102', '106']}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'ascii'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'encode'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'string', 'children': [], 'value': "'utf-8'"}, {'id': '109', 'type': 'call', 'children': ['110', '116']}; {'id': '110', 'type': 'attribute', 'children': ['111', '115']}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'ascii'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}, {'id': '117', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '118', 'type': 'if_statement', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'order'}; {'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': 'command'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '128', 'type': 'if_statement', 'children': ['129', '132']}, {'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': 'is'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'alpha'}, {'id': '131', 'type': 'True', 'children': []}; {'id': '132', 'type': 'block', 'children': ['133']}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'call', 'children': ['135', '138']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'command'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'string', 'children': [], 'value': "b'ALPHA'"}; {'id': '140', 'type': 'if_statement', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'store_as'}; {'id': '142', 'type': 'block', 'children': ['143']}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'augmented_assignment', 'children': ['145', '146'], 'value': '+='}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '146', 'type': 'list', 'children': ['147', '148'], 'value': "[b'STORE', store_as]"}, {'id': '147', 'type': 'string', 'children': [], 'value': "b'STORE'"}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'store_as'}, {'id': '149', 'type': 'return_statement', 'children': ['150']}; {'id': '150', 'type': 'call', 'children': ['151', '154']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': '_execute'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'command'}
def sort(self, key, by=None, external=None, offset=0, limit=None, order=None, alpha=False, store_as=None): if order and order not in [b'ASC', b'DESC', 'ASC', 'DESC']: raise ValueError('invalid sort order "{}"'.format(order)) command = [b'SORT', key] if by: command += [b'BY', by] if external and isinstance(external, list): for entry in external: command += [b'GET', entry] elif external: command += [b'GET', external] if limit: command += [ b'LIMIT', ascii(offset).encode('utf-8'), ascii(limit).encode('utf-8') ] if order: command.append(order) if alpha is True: command.append(b'ALPHA') if store_as: command += [b'STORE', store_as] return self._execute(command)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'zrange'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '13']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '11', 'type': 'unary_operator', 'children': ['12'], 'value': '-'}; {'id': '12', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'with_scores'}, {'id': '15', 'type': 'False', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17', '25', '33']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '20', 'type': 'list', 'children': ['21', '22', '23', '24'], 'value': "[b'ZRANGE', key, start, stop]"}, {'id': '21', 'type': 'string', 'children': [], 'value': "b'ZRANGE'"}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '25', 'type': 'if_statement', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'with_scores'}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'augmented_assignment', 'children': ['30', '31'], 'value': '+='}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'command'}, {'id': '31', 'type': 'list', 'children': ['32'], 'value': "['WITHSCORES']"}; {'id': '32', 'type': 'string', 'children': [], 'value': "'WITHSCORES'"}, {'id': '33', 'type': 'return_statement', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': '_execute'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'command'}
def zrange(self, key, start=0, stop=-1, with_scores=False): command = [b'ZRANGE', key, start, stop] if with_scores: command += ['WITHSCORES'] return self._execute(command)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'zrem'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '6', 'type': 'list_splat_pattern', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'members'}; {'id': '8', 'type': 'block', 'children': ['9']}, {'id': '9', 'type': 'return_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': '_execute'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'binary_operator', 'children': ['16', '19'], 'value': '+'}; {'id': '16', 'type': 'list', 'children': ['17', '18'], 'value': "[b'ZREM', key]"}, {'id': '17', 'type': 'string', 'children': [], 'value': "b'ZREM'"}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}
def zrem(self, key, *members): return self._execute([b'ZREM', key] + list(members))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'zremrangebyscore'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'min_score'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'max_score'}; {'id': '8', 'type': 'block', 'children': ['9']}, {'id': '9', 'type': 'return_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': '_execute'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'list', 'children': ['16', '17', '18', '19'], 'value': "[b'ZREMRANGEBYSCORE', key, min_score, max_score]"}; {'id': '16', 'type': 'string', 'children': [], 'value': "b'ZREMRANGEBYSCORE'"}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'min_score'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'max_score'}
def zremrangebyscore(self, key, min_score, max_score): return self._execute([b'ZREMRANGEBYSCORE', key, min_score, max_score])
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'zrevrange'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '13']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '11', 'type': 'unary_operator', 'children': ['12'], 'value': '-'}; {'id': '12', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'with_scores'}, {'id': '15', 'type': 'False', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17', '25', '33']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '20', 'type': 'list', 'children': ['21', '22', '23', '24'], 'value': "[b'ZREVRANGE', key, start, stop]"}, {'id': '21', 'type': 'string', 'children': [], 'value': "b'ZREVRANGE'"}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '25', 'type': 'if_statement', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'with_scores'}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'augmented_assignment', 'children': ['30', '31'], 'value': '+='}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'command'}, {'id': '31', 'type': 'list', 'children': ['32'], 'value': "['WITHSCORES']"}; {'id': '32', 'type': 'string', 'children': [], 'value': "'WITHSCORES'"}, {'id': '33', 'type': 'return_statement', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': '_execute'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'command'}
def zrevrange(self, key, start=0, stop=-1, with_scores=False): command = [b'ZREVRANGE', key, start, stop] if with_scores: command += ['WITHSCORES'] return self._execute(command)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_sortObjects'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'orderby'}; {'id': '6', 'type': 'string', 'children': [], 'value': "'created'"}, {'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '9', 'type': 'block', 'children': ['10', '14', '36', '46', '55', '83']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'o'}, {'id': '13', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '14', 'type': 'for_statement', 'children': ['15', '16', '21']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '20', 'type': 'argument_list', 'children': []}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'for_statement', 'children': ['23', '24', '28']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'iter'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '28', 'type': 'block', 'children': ['29']}, {'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': 'o'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'o'}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'sortfunc'}, {'id': '49', 'type': 'conditional_expression', 'children': ['50', '51', '54'], 'value': 'if'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': '_sortByCreated'}, {'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': '=='}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'orderby'}, {'id': '53', 'type': 'string', 'children': [], 'value': "'created'"}; {'id': '54', 'type': 'identifier', 'children': [], 'value': '_sortByModified'}, {'id': '55', 'type': 'if_statement', 'children': ['56', '59', '67']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'PY2'}, {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'sortfunc'}, {'id': '67', 'type': 'else_clause', 'children': ['68']}; {'id': '68', 'type': 'block', 'children': ['69']}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'o'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'functools'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'cmp_to_key'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'sortfunc'}, {'id': '83', 'type': 'return_statement', 'children': ['84']}
def _sortObjects(orderby='created', **kwargs): o = [] for m in kwargs.values(): for l in iter(m): o.append(l) o = list(set(o)) sortfunc = _sortByCreated if orderby == 'created' else _sortByModified if six.PY2: o.sort(sortfunc) else: o.sort(key=functools.cmp_to_key(sortfunc)) return o
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_sortByCreated'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '6', 'type': 'block', 'children': ['7']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '15', '18', '30']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '12'], 'value': '<'}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'created'}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'created'}, {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'return_statement', 'children': ['17']}, {'id': '17', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '18', 'type': 'elif_clause', 'children': ['19', '26']}, {'id': '19', 'type': 'comparison_operator', 'children': ['20', '23'], 'value': '>'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'created'}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'created'}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'return_statement', 'children': ['28']}; {'id': '28', 'type': 'unary_operator', 'children': ['29'], 'value': '-'}, {'id': '29', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '30', 'type': 'else_clause', 'children': ['31']}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'return_statement', 'children': ['33']}, {'id': '33', 'type': 'integer', 'children': [], 'value': '0'}
def _sortByCreated(a, b): if a.created < b.created: return 1 elif a.created > b.created: return -1 else: return 0
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_sortByModified'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '6', 'type': 'block', 'children': ['7']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '15', '18', '30']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '12'], 'value': '<'}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'modified'}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'modified'}, {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'return_statement', 'children': ['17']}, {'id': '17', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '18', 'type': 'elif_clause', 'children': ['19', '26']}, {'id': '19', 'type': 'comparison_operator', 'children': ['20', '23'], 'value': '>'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'modified'}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'modified'}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'return_statement', 'children': ['28']}; {'id': '28', 'type': 'unary_operator', 'children': ['29'], 'value': '-'}, {'id': '29', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '30', 'type': 'else_clause', 'children': ['31']}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'return_statement', 'children': ['33']}, {'id': '33', 'type': 'integer', 'children': [], 'value': '0'}
def _sortByModified(a, b): if a.modified < b.modified: return 1 elif a.modified > b.modified: return -1 else: return 0
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '31']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'wngram2idngram'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19', '22', '25', '28']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'input_file'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'vocab_file'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'output_file'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'buffersize'}, {'id': '9', 'type': 'integer', 'children': [], 'value': '100'}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'hashtablesize'}; {'id': '12', 'type': 'integer', 'children': [], 'value': '2000000'}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'files'}, {'id': '15', 'type': 'integer', 'children': [], 'value': '20'}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'compress'}; {'id': '18', 'type': 'False', 'children': []}, {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'verbosity'}, {'id': '21', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '22', 'type': 'default_parameter', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '25', 'type': 'default_parameter', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'write_ascii'}, {'id': '27', 'type': 'False', 'children': []}; {'id': '28', 'type': 'default_parameter', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'fof_size'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '10'}, {'id': '31', 'type': 'block', 'children': ['32', '55', '67', '79', '91', '103', '115', '127', '137', '147', '158', '259', '268', '284', '298', '322']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '35', 'type': 'list', 'children': ['36', '37', '38', '46', '47'], 'value': "['wngram2idngram', '-vocab', os.path.abspath(vocab_file),\n '-idngram', os.path.abspath(output_file)]"}; {'id': '36', 'type': 'string', 'children': [], 'value': "'wngram2idngram'"}, {'id': '37', 'type': 'string', 'children': [], 'value': "'-vocab'"}; {'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': 'os'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'abspath'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'vocab_file'}; {'id': '46', 'type': 'string', 'children': [], 'value': "'-idngram'"}, {'id': '47', 'type': 'call', 'children': ['48', '53']}; {'id': '48', 'type': 'attribute', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'abspath'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'output_file'}, {'id': '55', 'type': 'if_statement', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'buffersize'}, {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'list', 'children': ['65', '66'], 'value': "['-buffer', buffersize]"}, {'id': '65', 'type': 'string', 'children': [], 'value': "'-buffer'"}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'buffersize'}, {'id': '67', 'type': 'if_statement', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'hashtablesize'}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'list', 'children': ['77', '78'], 'value': "['-hash', hashtablesize]"}, {'id': '77', 'type': 'string', 'children': [], 'value': "'-hash'"}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'hashtablesize'}, {'id': '79', 'type': 'if_statement', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'files'}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'list', 'children': ['89', '90'], 'value': "['-files', files]"}, {'id': '89', 'type': 'string', 'children': [], 'value': "'-files'"}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'files'}, {'id': '91', 'type': 'if_statement', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'verbosity'}, {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'list', 'children': ['101', '102'], 'value': "['-verbosity', verbosity]"}, {'id': '101', 'type': 'string', 'children': [], 'value': "'-verbosity'"}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'verbosity'}, {'id': '103', 'type': 'if_statement', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'call', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'list', 'children': ['113', '114'], 'value': "['-n', n]"}, {'id': '113', 'type': 'string', 'children': [], 'value': "'-n'"}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '115', 'type': 'if_statement', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'fof_size'}, {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'list', 'children': ['125', '126'], 'value': "['-fof_size', fof_size]"}, {'id': '125', 'type': 'string', 'children': [], 'value': "'-fof_size'"}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'fof_size'}, {'id': '127', 'type': 'if_statement', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'compress'}, {'id': '129', 'type': 'block', 'children': ['130']}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'string', 'children': [], 'value': "'-compress'"}, {'id': '137', 'type': 'if_statement', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'write_ascii'}, {'id': '139', 'type': 'block', 'children': ['140']}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'string', 'children': [], 'value': "'-write_ascii'"}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '150', 'type': 'list_comprehension', 'children': ['151', '155']}, {'id': '151', 'type': 'call', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '155', 'type': 'for_in_clause', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '158', 'type': 'with_statement', 'children': ['159', '169']}, {'id': '159', 'type': 'with_clause', 'children': ['160']}; {'id': '160', 'type': 'with_item', 'children': ['161']}, {'id': '161', 'type': 'as_pattern', 'children': ['162', '167']}; {'id': '162', 'type': 'call', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'tempfile'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'SpooledTemporaryFile'}; {'id': '166', 'type': 'argument_list', 'children': []}, {'id': '167', 'type': 'as_pattern_target', 'children': ['168']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'output_f'}, {'id': '169', 'type': 'block', 'children': ['170', '251']}; {'id': '170', 'type': 'with_statement', 'children': ['171', '181']}, {'id': '171', 'type': 'with_clause', 'children': ['172']}; {'id': '172', 'type': 'with_item', 'children': ['173']}, {'id': '173', 'type': 'as_pattern', 'children': ['174', '179']}; {'id': '174', 'type': 'call', 'children': ['175', '178']}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'tempfile'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'SpooledTemporaryFile'}; {'id': '178', 'type': 'argument_list', 'children': []}, {'id': '179', 'type': 'as_pattern_target', 'children': ['180']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'input_f'}, {'id': '181', 'type': 'block', 'children': ['182', '209', '216']}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'call', 'children': ['184', '187']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'input_f'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'conditional_expression', 'children': ['189', '195', '208'], 'value': 'if'}, {'id': '189', 'type': 'call', 'children': ['190', '193']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'encode'}, {'id': '193', 'type': 'argument_list', 'children': ['194']}; {'id': '194', 'type': 'string', 'children': [], 'value': "'utf-8'"}, {'id': '195', 'type': 'boolean_operator', 'children': ['196', '202'], 'value': 'and'}; {'id': '196', 'type': 'comparison_operator', 'children': ['197', '200'], 'value': '>='}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'version_info'}; {'id': '200', 'type': 'tuple', 'children': ['201']}, {'id': '201', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '202', 'type': 'comparison_operator', 'children': ['203', '207'], 'value': 'is'}, {'id': '203', 'type': 'call', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'call', 'children': ['211', '214']}, {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'input_f'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'seek'}; {'id': '214', 'type': 'argument_list', 'children': ['215']}, {'id': '215', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '216', 'type': 'with_statement', 'children': ['217', '225']}, {'id': '217', 'type': 'with_clause', 'children': ['218']}; {'id': '218', 'type': 'with_item', 'children': ['219']}, {'id': '219', 'type': 'as_pattern', 'children': ['220', '223']}; {'id': '220', 'type': 'call', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'output_to_debuglogger'}; {'id': '222', 'type': 'argument_list', 'children': []}, {'id': '223', 'type': 'as_pattern_target', 'children': ['224']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'err_f'}, {'id': '225', 'type': 'block', 'children': ['226']}; {'id': '226', 'type': 'with_statement', 'children': ['227', '232']}, {'id': '227', 'type': 'with_clause', 'children': ['228']}; {'id': '228', 'type': 'with_item', 'children': ['229']}, {'id': '229', 'type': 'call', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'do_in_tempdir'}, {'id': '231', 'type': 'argument_list', 'children': []}; {'id': '232', 'type': 'block', 'children': ['233']}, {'id': '233', 'type': 'expression_statement', 'children': ['234']}; {'id': '234', 'type': 'assignment', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'exitcode'}; {'id': '236', 'type': 'call', 'children': ['237', '240']}, {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'subprocess'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'call'}; {'id': '240', 'type': 'argument_list', 'children': ['241', '242', '245', '248']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '242', 'type': 'keyword_argument', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'stdin'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'input_f'}, {'id': '245', 'type': 'keyword_argument', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'stdout'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'output_f'}; {'id': '248', 'type': 'keyword_argument', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'err_f'}, {'id': '251', 'type': 'expression_statement', 'children': ['252']}; {'id': '252', 'type': 'assignment', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '254', 'type': 'call', 'children': ['255', '258']}, {'id': '255', 'type': 'attribute', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'output_f'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '258', 'type': 'argument_list', 'children': []}, {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'assignment', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '262', 'type': 'call', 'children': ['263', '266']}, {'id': '263', 'type': 'attribute', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'getLogger'}; {'id': '266', 'type': 'argument_list', 'children': ['267']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '268', 'type': 'expression_statement', 'children': ['269']}, {'id': '269', 'type': 'call', 'children': ['270', '273']}; {'id': '270', 'type': 'attribute', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '273', 'type': 'argument_list', 'children': ['274']}; {'id': '274', 'type': 'binary_operator', 'children': ['275', '276'], 'value': '%'}, {'id': '275', 'type': 'string', 'children': [], 'value': '"Command \'%s\' returned with exit code \'%d\'."'}; {'id': '276', 'type': 'tuple', 'children': ['277', '283']}, {'id': '277', 'type': 'call', 'children': ['278', '281']}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}, {'id': '279', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '281', 'type': 'argument_list', 'children': ['282']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'exitcode'}; {'id': '284', 'type': 'if_statement', 'children': ['285', '288']}, {'id': '285', 'type': 'comparison_operator', 'children': ['286', '287'], 'value': '!='}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'exitcode'}, {'id': '287', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '288', 'type': 'block', 'children': ['289']}, {'id': '289', 'type': 'raise_statement', 'children': ['290']}; {'id': '290', 'type': 'call', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'ConversionError'}; {'id': '292', 'type': 'argument_list', 'children': ['293']}, {'id': '293', 'type': 'binary_operator', 'children': ['294', '295'], 'value': '%'}; {'id': '294', 'type': 'string', 'children': [], 'value': '"\'%r\' returned with non-zero exit status \'%s\'"'}, {'id': '295', 'type': 'tuple', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'exitcode'}; {'id': '298', 'type': 'if_statement', 'children': ['299', '312']}, {'id': '299', 'type': 'boolean_operator', 'children': ['300', '306'], 'value': 'and'}; {'id': '300', 'type': 'comparison_operator', 'children': ['301', '304'], 'value': '>='}, {'id': '301', 'type': 'attribute', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'version_info'}; {'id': '304', 'type': 'tuple', 'children': ['305']}, {'id': '305', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '306', 'type': 'comparison_operator', 'children': ['307', '311'], 'value': 'is'}, {'id': '307', 'type': 'call', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '309', 'type': 'argument_list', 'children': ['310']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'bytes'}; {'id': '312', 'type': 'block', 'children': ['313']}, {'id': '313', 'type': 'expression_statement', 'children': ['314']}; {'id': '314', 'type': 'assignment', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '316', 'type': 'call', 'children': ['317', '320']}, {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '320', 'type': 'argument_list', 'children': ['321']}, {'id': '321', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '322', 'type': 'return_statement', 'children': ['323']}, {'id': '323', 'type': 'call', 'children': ['324', '327']}; {'id': '324', 'type': 'attribute', 'children': ['325', '326']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '327', 'type': 'argument_list', 'children': []}
def wngram2idngram(input_file, vocab_file, output_file, buffersize=100, hashtablesize=2000000, files=20, compress=False, verbosity=2, n=3, write_ascii=False, fof_size=10): cmd = ['wngram2idngram', '-vocab', os.path.abspath(vocab_file), '-idngram', os.path.abspath(output_file)] if buffersize: cmd.extend(['-buffer', buffersize]) if hashtablesize: cmd.extend(['-hash', hashtablesize]) if files: cmd.extend(['-files', files]) if verbosity: cmd.extend(['-verbosity', verbosity]) if n: cmd.extend(['-n', n]) if fof_size: cmd.extend(['-fof_size', fof_size]) if compress: cmd.append('-compress') if write_ascii: cmd.append('-write_ascii') cmd = [str(x) for x in cmd] with tempfile.SpooledTemporaryFile() as output_f: with tempfile.SpooledTemporaryFile() as input_f: input_f.write(text.encode('utf-8') if sys.version_info >= (3,) and type(text) is str else text) input_f.seek(0) with output_to_debuglogger() as err_f: with do_in_tempdir(): exitcode = subprocess.call(cmd, stdin=input_f, stdout=output_f, stderr=err_f) output = output_f.read() logger = logging.getLogger(__name__) logger.debug("Command '%s' returned with exit code '%d'." % (' '.join(cmd), exitcode)) if exitcode != 0: raise ConversionError("'%r' returned with non-zero exit status '%s'" % (cmd, exitcode)) if sys.version_info >= (3,) and type(output) is bytes: output = output.decode('utf-8') return output.strip()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_top'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'stat'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'return_statement', 'children': ['9']}, {'id': '9', 'type': 'subscript', 'children': ['10', '29']}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '16', '26']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'stats'}; {'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '18', 'type': 'lambda', 'children': ['19', '21']}, {'id': '19', 'type': 'lambda_parameters', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'stat'}; {'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '28', 'type': 'True', 'children': []}, {'id': '29', 'type': 'slice', 'children': ['30', '31']}; {'id': '30', 'type': 'colon', 'children': []}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'n'}
def get_top(self, stat, n): return sorted(self.stats, key=lambda x: getattr(x, stat), reverse=True)[:n]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'toposort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'initialAtoms'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'initialBonds'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '17', '21', '27', '31', '35', '51', '63', '69', '74', '142', '152', '164', '178', '180', '185']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'atoms'}; {'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': 'a_append'}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'atoms'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'bonds'}; {'id': '20', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'b_append'}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'bonds'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'ahash'}; {'id': '30', 'type': 'dictionary', 'children': []}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'bhash'}; {'id': '34', 'type': 'dictionary', 'children': []}, {'id': '35', 'type': 'for_statement', 'children': ['36', '37', '42']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'atom'}, {'id': '37', 'type': 'subscript', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'initialAtoms'}, {'id': '39', 'type': 'slice', 'children': ['40', '41']}; {'id': '40', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '41', 'type': 'colon', 'children': []}; {'id': '42', 'type': 'block', 'children': ['43']}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '50']}, {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'ahash'}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'atom'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'handle'}; {'id': '50', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '51', 'type': 'for_statement', 'children': ['52', '53', '54']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'bond'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'initialBonds'}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '62']}, {'id': '57', 'type': 'subscript', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'bhash'}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'bond'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'handle'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'bond'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'initialAtoms'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'a_append'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '74', 'type': 'while_statement', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'ahash'}; {'id': '76', 'type': 'block', 'children': ['77']}, {'id': '77', 'type': 'for_statement', 'children': ['78', '79', '82', '135']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'atom'}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'next'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'oatoms'}; {'id': '82', 'type': 'block', 'children': ['83']}, {'id': '83', 'type': 'if_statement', 'children': ['84', '92']}; {'id': '84', 'type': 'call', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'ahash'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'has_key'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'atom'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'handle'}; {'id': '92', 'type': 'block', 'children': ['93', '102', '104']}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'bond'}; {'id': '96', 'type': 'call', 'children': ['97', '100']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'next'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'findbond'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'atom'}; {'id': '102', 'type': 'assert_statement', 'children': ['103']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'bond'}; {'id': '104', 'type': 'if_statement', 'children': ['105', '113']}, {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'bhash'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'has_key'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'bond'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'handle'}, {'id': '113', 'type': 'block', 'children': ['114', '119', '124', '130', '134']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'a_append'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'atom'}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'call', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'b_append'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'bond'}; {'id': '124', 'type': 'delete_statement', 'children': ['125']}, {'id': '125', 'type': 'subscript', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'ahash'}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'atom'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'handle'}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'assignment', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'next'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'atom'}; {'id': '134', 'type': 'break_statement', 'children': []}, {'id': '135', 'type': 'else_clause', 'children': ['136']}; {'id': '136', 'type': 'block', 'children': ['137']}, {'id': '137', 'type': 'raise_statement', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'RingException'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'string', 'children': [], 'value': '"Atoms are not in ring"'}; {'id': '142', 'type': 'assert_statement', 'children': ['143']}, {'id': '143', 'type': 'comparison_operator', 'children': ['144', '148'], 'value': '=='}; {'id': '144', 'type': 'call', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'initialAtoms'}; {'id': '148', 'type': 'call', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'atoms'}; {'id': '152', 'type': 'assert_statement', 'children': ['153']}, {'id': '153', 'type': 'comparison_operator', 'children': ['154', '158'], 'value': '=='}; {'id': '154', 'type': 'call', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'bonds'}; {'id': '158', 'type': 'binary_operator', 'children': ['159', '163'], 'value': '-'}, {'id': '159', 'type': 'call', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'atoms'}, {'id': '163', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'assignment', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'lastBond'}, {'id': '167', 'type': 'call', 'children': ['168', '173']}; {'id': '168', 'type': 'attribute', 'children': ['169', '172']}, {'id': '169', 'type': 'subscript', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'atoms'}, {'id': '171', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'findbond'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'subscript', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'atoms'}; {'id': '176', 'type': 'unary_operator', 'children': ['177'], 'value': '-'}, {'id': '177', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '178', 'type': 'assert_statement', 'children': ['179']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'lastBond'}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}, {'id': '181', 'type': 'call', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'b_append'}, {'id': '183', 'type': 'argument_list', 'children': ['184']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'lastBond'}, {'id': '185', 'type': 'return_statement', 'children': ['186']}; {'id': '186', 'type': 'expression_list', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'atoms'}
def toposort(initialAtoms, initialBonds): atoms = [] a_append = atoms.append bonds = [] b_append = bonds.append ahash = {} bhash = {} for atom in initialAtoms[1:]: ahash[atom.handle] = 1 for bond in initialBonds: bhash[bond.handle] = bond next = initialAtoms[0] a_append(next) while ahash: for atom in next.oatoms: if ahash.has_key(atom.handle): bond = next.findbond(atom) assert bond if bhash.has_key(bond.handle): a_append(atom) b_append(bond) del ahash[atom.handle] next = atom break else: raise RingException("Atoms are not in ring") assert len(initialAtoms) == len(atoms) assert len(bonds) == len(atoms) - 1 lastBond = atoms[0].findbond(atoms[-1]) assert lastBond b_append(lastBond) return atoms, bonds
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'flip_uuid_parts'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'uuid'}, {'id': '5', 'type': 'block', 'children': ['6', '15', '31', '40']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'flipped_uuid'}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'string', 'children': [], 'value': "'-'"}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '24']}, {'id': '17', 'type': 'pattern_list', 'children': ['18', '21']}; {'id': '18', 'type': 'subscript', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'flipped_uuid'}; {'id': '20', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '21', 'type': 'subscript', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'flipped_uuid'}, {'id': '23', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '24', 'type': 'expression_list', 'children': ['25', '28']}, {'id': '25', 'type': 'subscript', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'flipped_uuid'}, {'id': '27', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '28', 'type': 'subscript', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'flipped_uuid'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'flipped_uuid'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'string', 'children': [], 'value': "'-'"}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'flipped_uuid'}; {'id': '40', 'type': 'return_statement', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'flipped_uuid'}
def flip_uuid_parts(uuid): flipped_uuid = uuid.split('-') flipped_uuid[0], flipped_uuid[2] = flipped_uuid[2], flipped_uuid[0] flipped_uuid = '-'.join(flipped_uuid) return flipped_uuid
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'SortedSet'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'initial'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10']}; {'id': '10', 'type': 'return_statement', 'children': ['11']}, {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'types'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'SortedSet'}, {'id': '15', 'type': 'argument_list', 'children': ['16', '17', '20']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'api'}
def SortedSet(self, name, initial=None): return types.SortedSet(name, self.api, initial)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'member'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'score'}, {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'return_statement', 'children': ['9']}, {'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': 'client'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'zadd'}, {'id': '15', 'type': 'argument_list', 'children': ['16', '19', '20']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'member'}
def add(self, member, score): return self.client.zadd(self.name, member, score)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'deserialize'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '6', 'type': 'block', 'children': ['7', '16', '26', '36', '47']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'parsed'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'json'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'loads'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '16', 'type': 'if_statement', 'children': ['17', '20']}, {'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'not'}; {'id': '18', 'type': 'string', 'children': [], 'value': '"name"'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'parsed'}; {'id': '20', 'type': 'block', 'children': ['21']}, {'id': '21', 'type': 'raise_statement', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'string', 'children': [], 'value': '"No peer name."'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '30']}, {'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'not'}; {'id': '28', 'type': 'string', 'children': [], 'value': '"ip"'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'parsed'}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'raise_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'string', 'children': [], 'value': '"No peer IP."'}; {'id': '36', 'type': 'if_statement', 'children': ['37', '40']}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'not'}; {'id': '38', 'type': 'string', 'children': [], 'value': '"port"'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'parsed'}; {'id': '40', 'type': 'block', 'children': ['41']}, {'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': 'parsed'}, {'id': '45', 'type': 'string', 'children': [], 'value': '"port"'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_PEER_PORT'}, {'id': '47', 'type': 'return_statement', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '54', '57']}, {'id': '51', 'type': 'subscript', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'parsed'}, {'id': '53', 'type': 'string', 'children': [], 'value': '"name"'}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'parsed'}; {'id': '56', 'type': 'string', 'children': [], 'value': '"ip"'}, {'id': '57', 'type': 'subscript', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'parsed'}, {'id': '59', 'type': 'string', 'children': [], 'value': '"port"'}
def deserialize(cls, value): parsed = json.loads(value) if "name" not in parsed: raise ValueError("No peer name.") if "ip" not in parsed: raise ValueError("No peer IP.") if "port" not in parsed: parsed["port"] = DEFAULT_PEER_PORT return cls(parsed["name"], parsed["ip"], parsed["port"])
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'apply_config'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '6', 'type': 'block', 'children': ['7', '19', '37', '45', '57', '63', '73']}, {'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': 'host'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}, {'id': '17', 'type': 'string', 'children': [], 'value': '"host"'}; {'id': '18', 'type': 'string', 'children': [], 'value': '"127.0.0.1"'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'configured_ports'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30']}, {'id': '29', 'type': 'string', 'children': [], 'value': '"ports"'}; {'id': '30', 'type': 'list', 'children': ['31'], 'value': '[config.get("port")]'}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'string', 'children': [], 'value': '"port"'}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'discovery'}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '44', 'type': 'string', 'children': [], 'value': '"discovery"'}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56']}, {'id': '55', 'type': 'string', 'children': [], 'value': '"metadata"'}; {'id': '56', 'type': 'dictionary', 'children': []}, {'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': 'self'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'update_ports'}; {'id': '62', 'type': 'argument_list', 'children': []}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'check_interval'}; {'id': '68', 'type': 'subscript', 'children': ['69', '72']}, {'id': '69', 'type': 'subscript', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '71', 'type': 'string', 'children': [], 'value': '"checks"'}; {'id': '72', 'type': 'string', 'children': [], 'value': '"interval"'}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'update_checks'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'subscript', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '81', 'type': 'string', 'children': [], 'value': '"checks"'}
def apply_config(self, config): self.host = config.get("host", "127.0.0.1") self.configured_ports = config.get("ports", [config.get("port")]) self.discovery = config["discovery"] self.metadata = config.get("metadata", {}) self.update_ports() self.check_interval = config["checks"]["interval"] self.update_checks(config["checks"])
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_key'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '6', 'type': 'None', 'children': []}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'keyfile'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '68']}, {'id': '11', 'type': 'if_statement', 'children': ['12', '15']}; {'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'is'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'if_statement', 'children': ['17', '20', '54']}, {'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'keyfile'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21', '30']}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'environ'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'string', 'children': [], 'value': "'CRYPTOYAML_SECRET'"}; {'id': '30', 'type': 'if_statement', 'children': ['31', '34', '43']}, {'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'is'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '33', 'type': 'None', 'children': []}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'raise_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'MissingKeyException'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'concatenated_string', 'children': ['40', '41', '42']}; {'id': '40', 'type': 'string', 'children': [], 'value': "'''You must either provide a key value,'''"}, {'id': '41', 'type': 'string', 'children': [], 'value': "''' a path to a key or its value via the environment variable '''"}; {'id': '42', 'type': 'string', 'children': [], 'value': "''' CRYPTOYAML_SECRET'''"}, {'id': '43', 'type': 'else_clause', 'children': ['44']}; {'id': '44', 'type': 'block', 'children': ['45']}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '54', 'type': 'else_clause', 'children': ['55']}, {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '59', 'type': 'call', 'children': ['60', '67']}; {'id': '60', 'type': 'attribute', 'children': ['61', '66']}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'open'}, {'id': '63', 'type': 'argument_list', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'keyfile'}, {'id': '65', 'type': 'string', 'children': [], 'value': "'rb'"}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'read'}, {'id': '67', 'type': 'argument_list', 'children': []}; {'id': '68', 'type': 'return_statement', 'children': ['69']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'key'}
def get_key(key=None, keyfile=None): if key is None: if keyfile is None: key = environ.get('CRYPTOYAML_SECRET') if key is None: raise MissingKeyException( '''You must either provide a key value,''' ''' a path to a key or its value via the environment variable ''' ''' CRYPTOYAML_SECRET''' ) else: key = key.encode('utf-8') else: key = open(keyfile, 'rb').read() return key
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '27']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'getList'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'full_path'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'dept'}, {'id': '11', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '14', 'type': 'string', 'children': [], 'value': "'name'"}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '17', 'type': 'string', 'children': [], 'value': "'asc'"}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'startnum'}; {'id': '20', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'pagingrow'}, {'id': '23', 'type': 'integer', 'children': [], 'value': '1000'}; {'id': '24', 'type': 'default_parameter', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'dummy'}; {'id': '26', 'type': 'integer', 'children': [], 'value': '56184'}, {'id': '27', 'type': 'block', 'children': ['28', '41', '79', '91']}; {'id': '28', 'type': 'if_statement', 'children': ['29', '36']}, {'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'not'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '33', 'type': 'argument_list', 'children': ['34', '35']}; {'id': '34', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '36', 'type': 'block', 'children': ['37', '39']}, {'id': '37', 'type': 'print_statement', 'children': ['38']}; {'id': '38', 'type': 'string', 'children': [], 'value': '"Error getList: `type` should be between 1 to 5"'}, {'id': '39', 'type': 'return_statement', 'children': ['40']}; {'id': '40', 'type': 'False', 'children': []}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '44', 'type': 'dictionary', 'children': ['45', '48', '51', '54', '57', '60', '63', '66', '71', '76']}, {'id': '45', 'type': 'pair', 'children': ['46', '47']}; {'id': '46', 'type': 'string', 'children': [], 'value': "'orgresource'"}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'full_path'}; {'id': '48', 'type': 'pair', 'children': ['49', '50']}, {'id': '49', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '51', 'type': 'pair', 'children': ['52', '53']}; {'id': '52', 'type': 'string', 'children': [], 'value': "'dept'"}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'dept'}; {'id': '54', 'type': 'pair', 'children': ['55', '56']}, {'id': '55', 'type': 'string', 'children': [], 'value': "'sort'"}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '57', 'type': 'pair', 'children': ['58', '59']}; {'id': '58', 'type': 'string', 'children': [], 'value': "'order'"}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '60', 'type': 'pair', 'children': ['61', '62']}, {'id': '61', 'type': 'string', 'children': [], 'value': "'startnum'"}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'startnum'}, {'id': '63', 'type': 'pair', 'children': ['64', '65']}; {'id': '64', 'type': 'string', 'children': [], 'value': "'pagingrow'"}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'pagingrow'}; {'id': '66', 'type': 'pair', 'children': ['67', '68']}, {'id': '67', 'type': 'string', 'children': [], 'value': "'userid'"}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'user_id'}, {'id': '71', 'type': 'pair', 'children': ['72', '73']}; {'id': '72', 'type': 'string', 'children': [], 'value': "'useridx'"}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'useridx'}; {'id': '76', 'type': 'pair', 'children': ['77', '78']}, {'id': '77', 'type': 'string', 'children': [], 'value': "'dummy'"}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'dummy'}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '84']}, {'id': '81', 'type': 'pattern_list', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '84', 'type': 'call', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'POST'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '90']}, {'id': '89', 'type': 'string', 'children': [], 'value': "'getList'"}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '91', 'type': 'if_statement', 'children': ['92', '95', '98']}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': 'is'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '94', 'type': 'True', 'children': []}, {'id': '95', 'type': 'block', 'children': ['96']}; {'id': '96', 'type': 'return_statement', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '98', 'type': 'else_clause', 'children': ['99']}, {'id': '99', 'type': 'block', 'children': ['100', '102']}; {'id': '100', 'type': 'print_statement', 'children': ['101']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '102', 'type': 'return_statement', 'children': ['103']}, {'id': '103', 'type': 'False', 'children': []}
def getList(self, full_path, type = 1, dept = 0, sort = 'name', order = 'asc', startnum = 0, pagingrow = 1000, dummy = 56184): if type not in range(1, 6): print "Error getList: `type` should be between 1 to 5" return False data = {'orgresource': full_path, 'type': type, 'dept': dept, 'sort': sort, 'order': order, 'startnum': startnum, 'pagingrow': pagingrow, 'userid': self.user_id, 'useridx': self.useridx, 'dummy': dummy, } s, metadata = self.POST('getList', data) if s is True: return metadata else: print metadata return False
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_assignment_groups'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'course_id'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'exclude_assignment_submission_types'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'grading_period_id'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'include'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'override_assignment_dates'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'scope_assignments_to_student'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'block', 'children': ['22', '26', '30', '34', '40', '65', '88', '99', '110', '121', '142']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '25', 'type': 'dictionary', 'children': []}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '29', 'type': 'dictionary', 'children': []}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '33', 'type': 'dictionary', 'children': []}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '39']}; {'id': '36', 'type': 'subscript', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '38', 'type': 'string', 'children': [], 'value': '"course_id"'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'course_id'}; {'id': '40', 'type': 'if_statement', 'children': ['41', '44']}, {'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'is'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'include'}, {'id': '43', 'type': 'None', 'children': []}; {'id': '44', 'type': 'block', 'children': ['45', '59']}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': '_validate_enum'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'include'}; {'id': '52', 'type': 'list', 'children': ['53', '54', '55', '56', '57', '58'], 'value': '["assignments", "discussion_topic", "all_dates", "assignment_visibility", "overrides", "submission"]'}, {'id': '53', 'type': 'string', 'children': [], 'value': '"assignments"'}; {'id': '54', 'type': 'string', 'children': [], 'value': '"discussion_topic"'}, {'id': '55', 'type': 'string', 'children': [], 'value': '"all_dates"'}; {'id': '56', 'type': 'string', 'children': [], 'value': '"assignment_visibility"'}, {'id': '57', 'type': 'string', 'children': [], 'value': '"overrides"'}; {'id': '58', 'type': 'string', 'children': [], 'value': '"submission"'}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '64']}, {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '63', 'type': 'string', 'children': [], 'value': '"include"'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'include'}, {'id': '65', 'type': 'if_statement', 'children': ['66', '69']}; {'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': 'is'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'exclude_assignment_submission_types'}; {'id': '68', 'type': 'None', 'children': []}, {'id': '69', 'type': 'block', 'children': ['70', '82']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': '_validate_enum'}, {'id': '75', 'type': 'argument_list', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'exclude_assignment_submission_types'}, {'id': '77', 'type': 'list', 'children': ['78', '79', '80', '81'], 'value': '["online_quiz", "discussion_topic", "wiki_page", "external_tool"]'}; {'id': '78', 'type': 'string', 'children': [], 'value': '"online_quiz"'}, {'id': '79', 'type': 'string', 'children': [], 'value': '"discussion_topic"'}; {'id': '80', 'type': 'string', 'children': [], 'value': '"wiki_page"'}, {'id': '81', 'type': 'string', 'children': [], 'value': '"external_tool"'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '87']}; {'id': '84', 'type': 'subscript', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '86', 'type': 'string', 'children': [], 'value': '"exclude_assignment_submission_types"'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'exclude_assignment_submission_types'}; {'id': '88', 'type': 'if_statement', 'children': ['89', '92']}, {'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': 'is'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'override_assignment_dates'}, {'id': '91', 'type': 'None', 'children': []}; {'id': '92', 'type': 'block', 'children': ['93']}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '98']}, {'id': '95', 'type': 'subscript', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '97', 'type': 'string', 'children': [], 'value': '"override_assignment_dates"'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'override_assignment_dates'}, {'id': '99', 'type': 'if_statement', 'children': ['100', '103']}; {'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': 'is'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'grading_period_id'}; {'id': '102', 'type': 'None', 'children': []}, {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '109']}; {'id': '106', 'type': 'subscript', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '108', 'type': 'string', 'children': [], 'value': '"grading_period_id"'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'grading_period_id'}; {'id': '110', 'type': 'if_statement', 'children': ['111', '114']}, {'id': '111', 'type': 'comparison_operator', 'children': ['112', '113'], 'value': 'is'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'scope_assignments_to_student'}, {'id': '113', 'type': 'None', 'children': []}; {'id': '114', 'type': 'block', 'children': ['115']}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '120']}, {'id': '117', 'type': 'subscript', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '119', 'type': 'string', 'children': [], 'value': '"scope_assignments_to_student"'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'scope_assignments_to_student'}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '128']}, {'id': '123', 'type': 'attribute', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}, {'id': '129', 'type': 'call', 'children': ['130', '133']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'string', 'children': [], 'value': '"GET /api/v1/courses/{course_id}/assignment_groups with query params: {params} and form data: {data}"'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '133', 'type': 'argument_list', 'children': ['134', '137', '140']}; {'id': '134', 'type': 'keyword_argument', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '140', 'type': 'dictionary_splat', 'children': ['141']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '142', 'type': 'return_statement', 'children': ['143']}, {'id': '143', 'type': 'call', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'generic_request'}, {'id': '147', 'type': 'argument_list', 'children': ['148', '149', '156', '159', '162']}; {'id': '148', 'type': 'string', 'children': [], 'value': '"GET"'}, {'id': '149', 'type': 'call', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'string', 'children': [], 'value': '"/api/v1/courses/{course_id}/assignment_groups"'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'dictionary_splat', 'children': ['155']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '156', 'type': 'keyword_argument', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '159', 'type': 'keyword_argument', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '162', 'type': 'keyword_argument', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'all_pages'}
def list_assignment_groups(self, course_id, exclude_assignment_submission_types=None, grading_period_id=None, include=None, override_assignment_dates=None, scope_assignments_to_student=None): path = {} data = {} params = {} path["course_id"] = course_id if include is not None: self._validate_enum(include, ["assignments", "discussion_topic", "all_dates", "assignment_visibility", "overrides", "submission"]) params["include"] = include if exclude_assignment_submission_types is not None: self._validate_enum(exclude_assignment_submission_types, ["online_quiz", "discussion_topic", "wiki_page", "external_tool"]) params["exclude_assignment_submission_types"] = exclude_assignment_submission_types if override_assignment_dates is not None: params["override_assignment_dates"] = override_assignment_dates if grading_period_id is not None: params["grading_period_id"] = grading_period_id if scope_assignments_to_student is not None: params["scope_assignments_to_student"] = scope_assignments_to_student self.logger.debug("GET /api/v1/courses/{course_id}/assignment_groups with query params: {params} and form data: {data}".format(params=params, data=data, **path)) return self.generic_request("GET", "/api/v1/courses/{course_id}/assignment_groups".format(**path), data=data, params=params, all_pages=True)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_sorted_keys'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '39']}; {'id': '6', 'type': 'try_statement', 'children': ['7', '16']}, {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '11', 'type': 'subscript', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_cache'}, {'id': '15', 'type': 'string', 'children': [], 'value': "'sorted_keys'"}; {'id': '16', 'type': 'except_clause', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'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': 'keys'}; {'id': '22', 'type': 'assignment', 'children': ['23', '28']}, {'id': '23', 'type': 'subscript', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '_cache'}, {'id': '27', 'type': 'string', 'children': [], 'value': "'sorted_keys'"}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '36']}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'parse_version'}, {'id': '39', 'type': 'return_statement', 'children': ['40']}
def _sorted_keys(self): try: keys = self._cache['sorted_keys'] except KeyError: keys = self._cache['sorted_keys'] = sorted(self.keys(), key=parse_version) return keys
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'query'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'filters'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '17', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '20', 'type': 'integer', 'children': [], 'value': '30'}, {'id': '21', 'type': 'block', 'children': ['22', '32', '65', '85', '127', '144', '152', '166', '176', '182', '186', '212', '216', '225']}; {'id': '22', 'type': 'if_statement', 'children': ['23', '25']}, {'id': '23', 'type': 'not_operator', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '29', 'type': 'list', 'children': ['30', '31'], 'value': '["*", "score"]'}; {'id': '30', 'type': 'string', 'children': [], 'value': '"*"'}, {'id': '31', 'type': 'string', 'children': [], 'value': '"score"'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '35', 'type': 'dictionary', 'children': ['36', '39', '42', '50', '56', '62']}; {'id': '36', 'type': 'pair', 'children': ['37', '38']}, {'id': '37', 'type': 'string', 'children': [], 'value': '"q"'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '39', 'type': 'pair', 'children': ['40', '41']}; {'id': '40', 'type': 'string', 'children': [], 'value': '"json.nl"'}, {'id': '41', 'type': 'string', 'children': [], 'value': '"map"'}; {'id': '42', 'type': 'pair', 'children': ['43', '44']}, {'id': '43', 'type': 'string', 'children': [], 'value': '"fl"'}; {'id': '44', 'type': 'call', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'string', 'children': [], 'value': '","'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '50', 'type': 'pair', 'children': ['51', '52']}, {'id': '51', 'type': 'string', 'children': [], 'value': '"start"'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '56', 'type': 'pair', 'children': ['57', '58']}, {'id': '57', 'type': 'string', 'children': [], 'value': '"rows"'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '62', 'type': 'pair', 'children': ['63', '64']}, {'id': '63', 'type': 'string', 'children': [], 'value': '"wt"'}; {'id': '64', 'type': 'string', 'children': [], 'value': '"json"'}, {'id': '65', 'type': 'if_statement', 'children': ['66', '74']}; {'id': '66', 'type': 'comparison_operator', 'children': ['67', '73'], 'value': '>'}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'endpoints'}, {'id': '73', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '74', 'type': 'block', 'children': ['75']}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '80']}, {'id': '77', 'type': 'subscript', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '79', 'type': 'string', 'children': [], 'value': '"shards"'}; {'id': '80', 'type': 'call', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': '_get_shards'}; {'id': '84', 'type': 'argument_list', 'children': []}, {'id': '85', 'type': 'if_statement', 'children': ['86', '90']}; {'id': '86', 'type': 'not_operator', 'children': ['87']}, {'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': 'is'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'filters'}, {'id': '89', 'type': 'None', 'children': []}; {'id': '90', 'type': 'block', 'children': ['91', '95', '116']}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'filter_list'}; {'id': '94', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '95', 'type': 'for_statement', 'children': ['96', '99', '104']}; {'id': '96', 'type': 'pattern_list', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'filter_field'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'filters'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '103', 'type': 'argument_list', 'children': []}; {'id': '104', 'type': 'block', 'children': ['105']}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'call', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'filter_list'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'binary_operator', 'children': ['112', '113'], 'value': '%'}; {'id': '112', 'type': 'string', 'children': [], 'value': '"%s:%s"'}, {'id': '113', 'type': 'tuple', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'filter_field'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '121']}; {'id': '118', 'type': 'subscript', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '120', 'type': 'string', 'children': [], 'value': '"fq"'}, {'id': '121', 'type': 'call', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'string', 'children': [], 'value': '" AND "'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'filter_list'}, {'id': '127', 'type': 'if_statement', 'children': ['128', '132']}; {'id': '128', 'type': 'not_operator', 'children': ['129']}, {'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': 'is'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '131', 'type': 'None', 'children': []}; {'id': '132', 'type': 'block', 'children': ['133']}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '138']}, {'id': '135', 'type': 'subscript', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '137', 'type': 'string', 'children': [], 'value': '"sort"'}; {'id': '138', 'type': 'call', 'children': ['139', '142']}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'string', 'children': [], 'value': '","'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '144', 'type': 'assert_statement', 'children': ['145']}, {'id': '145', 'type': 'comparison_operator', 'children': ['146', '149'], 'value': 'in'}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'default_endpoint'}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'endpoints'}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'request_url'}, {'id': '155', 'type': 'call', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': '_get_url'}, {'id': '157', 'type': 'argument_list', 'children': ['158', '165']}; {'id': '158', 'type': 'subscript', 'children': ['159', '162']}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'endpoints'}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'default_endpoint'}, {'id': '165', 'type': 'string', 'children': [], 'value': '"select"'}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'assignment', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': '_send_solr_query'}, {'id': '173', 'type': 'argument_list', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'request_url'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '176', 'type': 'if_statement', 'children': ['177', '179']}, {'id': '177', 'type': 'not_operator', 'children': ['178']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '179', 'type': 'block', 'children': ['180']}; {'id': '180', 'type': 'return_statement', 'children': ['181']}, {'id': '181', 'type': 'None', 'children': []}; {'id': '182', 'type': 'assert_statement', 'children': ['183']}, {'id': '183', 'type': 'comparison_operator', 'children': ['184', '185'], 'value': 'in'}; {'id': '184', 'type': 'string', 'children': [], 'value': '"responseHeader"'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '186', 'type': 'if_statement', 'children': ['187', '201']}, {'id': '187', 'type': 'not_operator', 'children': ['188']}; {'id': '188', 'type': 'comparison_operator', 'children': ['189', '200'], 'value': '=='}, {'id': '189', 'type': 'call', 'children': ['190', '198']}; {'id': '190', 'type': 'attribute', 'children': ['191', '197']}, {'id': '191', 'type': 'call', 'children': ['192', '195']}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'string', 'children': [], 'value': '"responseHeader"'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '198', 'type': 'argument_list', 'children': ['199']}, {'id': '199', 'type': 'string', 'children': [], 'value': '"status"'}; {'id': '200', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '201', 'type': 'block', 'children': ['202', '210']}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'call', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '207', 'type': 'argument_list', 'children': ['208', '209']}; {'id': '208', 'type': 'string', 'children': [], 'value': '"Server error while retrieving results: %s"'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '210', 'type': 'return_statement', 'children': ['211']}, {'id': '211', 'type': 'None', 'children': []}; {'id': '212', 'type': 'assert_statement', 'children': ['213']}, {'id': '213', 'type': 'comparison_operator', 'children': ['214', '215'], 'value': 'in'}; {'id': '214', 'type': 'string', 'children': [], 'value': '"response"'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}, {'id': '217', 'type': 'assignment', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'result_obj'}, {'id': '219', 'type': 'call', 'children': ['220', '223']}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': '_parse_response'}, {'id': '223', 'type': 'argument_list', 'children': ['224']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '225', 'type': 'return_statement', 'children': ['226']}
def query(self, query, filters=None, columns=None, sort=None, start=0, rows=30): if not columns: columns = ["*", "score"] fields = {"q": query, "json.nl" :"map", "fl": ",".join(columns), "start": str(start), "rows": str(rows), "wt": "json"} if len(self.endpoints) > 1: fields["shards"] = self._get_shards() if not filters is None: filter_list = [] for filter_field, value in filters.items(): filter_list.append("%s:%s" % (filter_field, value)) fields["fq"] = " AND ".join(filter_list) if not sort is None: fields["sort"] = ",".join(sort) assert self.default_endpoint in self.endpoints request_url = _get_url(self.endpoints[self.default_endpoint], "select") results = self._send_solr_query(request_url, fields) if not results: return None assert "responseHeader" in results if not results.get("responseHeader").get("status") == 0: logger.error("Server error while retrieving results: %s", results) return None assert "response" in results result_obj = self._parse_response(results) return result_obj
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'search_videohub'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'filters'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'status'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'size'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'block', 'children': ['22', '33', '45', '52', '67', '94', '109', '128', '147', '167', '180']}; {'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', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '29', '30']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'settings'}, {'id': '29', 'type': 'string', 'children': [], 'value': '"VIDEOHUB_API_SEARCH_URL"'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_VIDEOHUB_API_SEARCH_URL'}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '36', 'type': 'dictionary', 'children': ['37', '40']}, {'id': '37', 'type': 'pair', 'children': ['38', '39']}; {'id': '38', 'type': 'string', 'children': [], 'value': '"Content-Type"'}, {'id': '39', 'type': 'string', 'children': [], 'value': '"application/json"'}; {'id': '40', 'type': 'pair', 'children': ['41', '42']}, {'id': '41', 'type': 'string', 'children': [], 'value': '"Authorization"'}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'VIDEOHUB_API_TOKEN'}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'payload'}; {'id': '48', 'type': 'dictionary', 'children': ['49']}, {'id': '49', 'type': 'pair', 'children': ['50', '51']}; {'id': '50', 'type': 'string', 'children': [], 'value': '"query"'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '52', 'type': 'if_statement', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'filters'}; {'id': '54', 'type': 'block', 'children': ['55', '61']}, {'id': '55', 'type': 'assert_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'filters'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '66']}, {'id': '63', 'type': 'subscript', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'payload'}, {'id': '65', 'type': 'string', 'children': [], 'value': '"filters"'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'filters'}, {'id': '67', 'type': 'if_statement', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'status'}, {'id': '69', 'type': 'block', 'children': ['70', '78', '86']}; {'id': '70', 'type': 'assert_statement', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '73', 'type': 'argument_list', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'status'}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'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': 'payload'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'setdefault'}, {'id': '83', 'type': 'argument_list', 'children': ['84', '85']}; {'id': '84', 'type': 'string', 'children': [], 'value': '"filters"'}, {'id': '85', 'type': 'dictionary', 'children': []}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '93']}; {'id': '88', 'type': 'subscript', 'children': ['89', '92']}, {'id': '89', 'type': 'subscript', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'payload'}, {'id': '91', 'type': 'string', 'children': [], 'value': '"filters"'}; {'id': '92', 'type': 'string', 'children': [], 'value': '"status"'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '94', 'type': 'if_statement', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '96', 'type': 'block', 'children': ['97', '103']}, {'id': '97', 'type': 'assert_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '100', 'type': 'argument_list', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '108']}, {'id': '105', 'type': 'subscript', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'payload'}, {'id': '107', 'type': 'string', 'children': [], 'value': '"sort"'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '109', 'type': 'if_statement', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'size'}, {'id': '111', 'type': 'block', 'children': ['112', '122']}; {'id': '112', 'type': 'assert_statement', 'children': ['113']}, {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '115', 'type': 'argument_list', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'size'}, {'id': '117', 'type': 'tuple', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'string_types'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'assignment', 'children': ['124', '127']}; {'id': '124', 'type': 'subscript', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'payload'}; {'id': '126', 'type': 'string', 'children': [], 'value': '"size"'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '128', 'type': 'if_statement', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '130', 'type': 'block', 'children': ['131', '141']}, {'id': '131', 'type': 'assert_statement', 'children': ['132']}; {'id': '132', 'type': 'call', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '134', 'type': 'argument_list', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '136', 'type': 'tuple', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '146']}, {'id': '143', 'type': 'subscript', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'payload'}, {'id': '145', 'type': 'string', 'children': [], 'value': '"page"'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'page'}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '150', 'type': 'call', 'children': ['151', '154']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'requests'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'post'}; {'id': '154', 'type': 'argument_list', 'children': ['155', '156', '164']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '156', 'type': 'keyword_argument', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '158', 'type': 'call', 'children': ['159', '162']}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'json'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'dumps'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'payload'}; {'id': '164', 'type': 'keyword_argument', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '167', 'type': 'if_statement', 'children': ['168', '173']}; {'id': '168', 'type': 'comparison_operator', 'children': ['169', '172'], 'value': '!='}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'status_code'}; {'id': '172', 'type': 'integer', 'children': [], 'value': '200'}, {'id': '173', 'type': 'block', 'children': ['174']}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'call', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'raise_for_status'}, {'id': '179', 'type': 'argument_list', 'children': []}; {'id': '180', 'type': 'return_statement', 'children': ['181']}, {'id': '181', 'type': 'call', 'children': ['182', '185']}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'loads'}, {'id': '185', 'type': 'argument_list', 'children': ['186']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'res'}
def search_videohub(cls, query, filters=None, status=None, sort=None, size=None, page=None): url = getattr(settings, "VIDEOHUB_API_SEARCH_URL", cls.DEFAULT_VIDEOHUB_API_SEARCH_URL) headers = { "Content-Type": "application/json", "Authorization": settings.VIDEOHUB_API_TOKEN, } payload = { "query": query, } if filters: assert isinstance(filters, dict) payload["filters"] = filters if status: assert isinstance(status, six.string_types) payload.setdefault("filters", {}) payload["filters"]["status"] = status if sort: assert isinstance(sort, dict) payload["sort"] = sort if size: assert isinstance(size, (six.string_types, int)) payload["size"] = size if page: assert isinstance(page, (six.string_types, int)) payload["page"] = page res = requests.post(url, data=json.dumps(payload), headers=headers) if res.status_code != 200: res.raise_for_status() return json.loads(res.content)
{'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': 'key'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '7', 'type': 'block', 'children': ['8', '15', '25']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': '_find_lte'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': '_create_node'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': '_insert'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'node'}
def insert(self, key, value): self._find_lte(key) node = self._create_node(key, value) self._insert(node)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'list_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sorting'}, {'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '9', 'type': 'block', 'children': ['10', '14', '61', '74']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sorting_'}, {'id': '13', 'type': 'list', 'children': [], 'value': '[]'}; {'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': 'desc'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'sorting'}, {'id': '19', 'type': 'block', 'children': ['20', '37', '43', '54']}; {'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', '35']}; {'id': '24', 'type': 'attribute', 'children': ['25', '34']}, {'id': '25', 'type': 'attribute', 'children': ['26', '33']}; {'id': '26', 'type': 'attribute', 'children': ['27', '32']}, {'id': '27', 'type': 'attribute', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'meta'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '_meta'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '37', 'type': 'if_statement', 'children': ['38', '41']}; {'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': 'is'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '40', 'type': 'None', 'children': []}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'continue_statement', 'children': []}, {'id': '43', 'type': 'if_statement', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'desc'}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'desc'}, {'id': '53', 'type': 'argument_list', 'children': []}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'sorting_'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '61', 'type': 'if_statement', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'sorting_'}, {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'return_statement', 'children': ['65']}, {'id': '65', 'type': 'call', 'children': ['66', '71']}; {'id': '66', 'type': 'attribute', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'collection'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'order_by'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'list_splat', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'sorting_'}; {'id': '74', 'type': 'return_statement', 'children': ['75']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'collection'}
def sort(self, *sorting, **kwargs): sorting_ = [] for name, desc in sorting: field = self.meta.model._meta.fields.get(name) if field is None: continue if desc: field = field.desc() sorting_.append(field) if sorting_: return self.collection.order_by(*sorting_) return self.collection
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'split'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '6', 'type': 'block', 'children': ['7']}, {'id': '7', 'type': 'return_statement', 'children': ['8']}; {'id': '8', 'type': 'list_comprehension', 'children': ['9', '16']}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'LogicalNetworkList'}, {'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': 'hg'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'part'}; {'id': '16', 'type': 'for_in_clause', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'part'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': '__matrix'}
def split(self, indices): return [LogicalNetworkList(self.hg, part) for part in np.split(self.__matrix, indices)]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'movies_box_office'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '7', 'type': 'block', 'children': ['8', '17', '27', '34']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'path'}, {'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': '_get_path'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'string', 'children': [], 'value': "'movies_box_office'"}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'response'}; {'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': '_GET'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': '_set_attrs_to_values'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '34', 'type': 'return_statement', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'response'}
def movies_box_office(self, **kwargs): path = self._get_path('movies_box_office') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_parents'}, {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '14', '28', '49']}, {'id': '5', 'type': 'expression_statement', 'children': ['6']}; {'id': '6', 'type': 'assignment', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'distributions'}; {'id': '8', 'type': 'call', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'get_installed_distributions'}; {'id': '10', 'type': 'argument_list', 'children': ['11']}, {'id': '11', 'type': 'keyword_argument', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'user_only'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ENABLE_USER_SITE'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'remaining'}, {'id': '17', 'type': 'set_comprehension', 'children': ['18', '25']}; {'id': '18', 'type': 'call', 'children': ['19', '24']}, {'id': '19', 'type': 'attribute', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'project_name'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '24', 'type': 'argument_list', 'children': []}, {'id': '25', 'type': 'for_in_clause', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'distributions'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'requirements'}, {'id': '31', 'type': 'set_comprehension', 'children': ['32', '39', '42']}; {'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': 'r'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'project_name'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '38', 'type': 'argument_list', 'children': []}, {'id': '39', 'type': 'for_in_clause', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'distributions'}; {'id': '42', 'type': 'for_in_clause', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '44', 'type': 'call', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'requires'}; {'id': '48', 'type': 'argument_list', 'children': []}, {'id': '49', 'type': 'return_statement', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'get_realnames'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'binary_operator', 'children': ['54', '55'], 'value': '-'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'remaining'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'requirements'}
def get_parents(): distributions = get_installed_distributions(user_only=ENABLE_USER_SITE) remaining = {d.project_name.lower() for d in distributions} requirements = {r.project_name.lower() for d in distributions for r in d.requires()} return get_realnames(remaining - requirements)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_realnames'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'packages'}, {'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', '20']}; {'id': '10', 'type': 'set_comprehension', 'children': ['11', '17']}, {'id': '11', 'type': 'attribute', 'children': ['12', '16']}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'get_distribution'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'project_name'}, {'id': '17', 'type': 'for_in_clause', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'packages'}; {'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': 'n'}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '29', 'type': 'argument_list', 'children': []}
def get_realnames(packages): return sorted({get_distribution(p).project_name for p in packages}, key=lambda n: n.lower())
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_sort'}, {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '7', '18', '30', '43']}, {'id': '5', 'type': 'expression_statement', 'children': ['6']}; {'id': '6', 'type': 'string', 'children': [], 'value': "'''Build sort query paramter from kwargs'''"}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sorts'}; {'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': 'request'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'getlist'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'string', 'children': [], 'value': "'sort'"}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'sorts'}, {'id': '21', 'type': 'conditional_expression', 'children': ['22', '24', '29'], 'value': 'if'}; {'id': '22', 'type': 'list', 'children': ['23'], 'value': '[sorts]'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'sorts'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sorts'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'basestring'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'sorts'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'sorts'}, {'id': '33', 'type': 'list_comprehension', 'children': ['34', '40']}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '40', 'type': 'for_in_clause', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'sorts'}, {'id': '43', 'type': 'return_statement', 'children': ['44']}; {'id': '44', 'type': 'list_comprehension', 'children': ['45', '51', '56']}, {'id': '45', 'type': 'dictionary', 'children': ['46']}; {'id': '46', 'type': 'pair', 'children': ['47', '50']}, {'id': '47', 'type': 'subscript', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'SORTS'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '51', 'type': 'for_in_clause', 'children': ['52', '55']}; {'id': '52', 'type': 'pattern_list', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'sorts'}; {'id': '56', 'type': 'if_clause', 'children': ['57']}, {'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': 'in'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'SORTS'}
def build_sort(): '''Build sort query paramter from kwargs''' sorts = request.args.getlist('sort') sorts = [sorts] if isinstance(sorts, basestring) else sorts sorts = [s.split(' ') for s in sorts] return [{SORTS[s]: d} for s, d in sorts if s in SORTS]
{'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': 'transactions'}, {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'return_statement', 'children': ['7']}, {'id': '7', 'type': 'subscript', 'children': ['8', '34']}; {'id': '8', 'type': 'call', 'children': ['9', '12']}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'transactions'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'keyword_argument', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '15', 'type': 'lambda', 'children': ['16', '18']}; {'id': '16', 'type': 'lambda_parameters', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '18', 'type': 'call', 'children': ['19', '24']}, {'id': '19', 'type': 'attribute', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'strptime'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '33']}, {'id': '25', 'type': 'subscript', 'children': ['26', '32']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'string', 'children': [], 'value': "':'"}; {'id': '32', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '33', 'type': 'string', 'children': [], 'value': "'%Y-%m-%d'"}; {'id': '34', 'type': 'slice', 'children': ['35']}, {'id': '35', 'type': 'colon', 'children': []}
def sort(transactions): return transactions.sort(key=lambda x: datetime.datetime.strptime(x.split(':')[0], '%Y-%m-%d'))[:]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'duplicates'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '6', 'type': 'block', 'children': ['7']}, {'id': '7', 'type': 'for_statement', 'children': ['8', '9', '10']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '10', 'type': 'block', 'children': ['11']}, {'id': '11', 'type': 'if_statement', 'children': ['12', '26']}; {'id': '12', 'type': 'boolean_operator', 'children': ['13', '19'], 'value': 'and'}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'similarity'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '19', 'type': 'not_operator', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'equality'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'yield', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'item'}
def duplicates(base, items): for item in items: if item.similarity(base) and not item.equality(base): yield item
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '6', 'type': 'block', 'children': ['7']}, {'id': '7', 'type': 'return_statement', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '10', 'type': 'argument_list', 'children': ['11', '12', '17']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '12', 'type': 'keyword_argument', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'similarity'}, {'id': '17', 'type': 'keyword_argument', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '19', 'type': 'True', 'children': []}
def sort(base, items): return sorted(items, key=base.similarity, reverse=True)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'Subclasses'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort_by'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '18', '48', '57', '82']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'for_statement', 'children': ['19', '22', '26']}, {'id': '19', 'type': 'pattern_list', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'get_all_attributes'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'try_statement', 'children': ['28', '45']}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'if_statement', 'children': ['30', '35']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'issubclass'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'Constant'}, {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'tuple', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '45', 'type': 'except_clause', 'children': ['46']}; {'id': '46', 'type': 'block', 'children': ['47']}, {'id': '47', 'type': 'pass_statement', 'children': []}; {'id': '48', 'type': 'if_statement', 'children': ['49', '52']}, {'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'is'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'sort_by'}, {'id': '51', 'type': 'None', 'children': []}; {'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': 'sort_by'}; {'id': '56', 'type': 'string', 'children': [], 'value': '"__creation_index__"'}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '67', '79']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '69', 'type': 'lambda', 'children': ['70', '72']}; {'id': '70', 'type': 'lambda_parameters', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '74', 'type': 'argument_list', 'children': ['75', '78']}, {'id': '75', 'type': 'subscript', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '77', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'sort_by'}, {'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '82', 'type': 'return_statement', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'l'}
def Subclasses(cls, sort_by=None, reverse=False): l = list() for attr, value in get_all_attributes(cls): try: if issubclass(value, Constant): l.append((attr, value)) except: pass if sort_by is None: sort_by = "__creation_index__" l = list( sorted(l, key=lambda x: getattr(x[1], sort_by), reverse=reverse)) return l
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'subclasses'}, {'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': 'sort_by'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '18', '47']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'for_statement', 'children': ['19', '22', '29']}, {'id': '19', 'type': 'pattern_list', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'Subclasses'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sort_by'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'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': 'value'}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '35', 'type': 'argument_list', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'tuple', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '47', 'type': 'return_statement', 'children': ['48']}
def subclasses(self, sort_by=None, reverse=False): l = list() for attr, _ in self.Subclasses(sort_by, reverse): value = getattr(self, attr) l.append((attr, value)) return l
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'organize_dir'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'orig_dir'}, {'id': '5', 'type': 'block', 'children': ['6', '8', '24', '33', '46', '53', '109', '116', '122', '342']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'string', 'children': [], 'value': "'''scans through the given directory and organizes DICOMs that look similar into subdirectories\n output directory is the ``orig_dir`` with ``-sorted`` appended to the end'''"}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'tags'}, {'id': '11', 'type': 'list', 'children': ['12', '15', '18', '21'], 'value': '[\n (0x10,0x20),\n (0x8,0x21),\n (0x8,0x31),\n (0x8,0x103e)\n ]'}; {'id': '12', 'type': 'tuple', 'children': ['13', '14']}, {'id': '13', 'type': 'integer', 'children': [], 'value': '0x10'}; {'id': '14', 'type': 'integer', 'children': [], 'value': '0x20'}, {'id': '15', 'type': 'tuple', 'children': ['16', '17']}; {'id': '16', 'type': 'integer', 'children': [], 'value': '0x8'}, {'id': '17', 'type': 'integer', 'children': [], 'value': '0x21'}; {'id': '18', 'type': 'tuple', 'children': ['19', '20']}, {'id': '19', 'type': 'integer', 'children': [], 'value': '0x8'}; {'id': '20', 'type': 'integer', 'children': [], 'value': '0x31'}, {'id': '21', 'type': 'tuple', 'children': ['22', '23']}; {'id': '22', 'type': 'integer', 'children': [], 'value': '0x8'}, {'id': '23', 'type': 'integer', 'children': [], 'value': '0x103e'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'orig_dir'}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'orig_dir'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'rstrip'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'files'}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'scan_dir'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40', '43']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'orig_dir'}; {'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'tags'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'tags'}, {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'md5_hash'}, {'id': '45', 'type': 'True', 'children': []}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'dups'}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'find_dups'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'files'}, {'id': '53', 'type': 'for_statement', 'children': ['54', '55', '56']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'dup'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'dups'}; {'id': '56', 'type': 'block', 'children': ['57', '68']}, {'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': 'nl'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'notify'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'binary_operator', 'children': ['64', '65'], 'value': '%'}; {'id': '64', 'type': 'string', 'children': [], 'value': "'Found duplicates of %s...'"}, {'id': '65', 'type': 'subscript', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'dup'}, {'id': '67', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '68', 'type': 'for_statement', 'children': ['69', '70', '75']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'each_dup'}; {'id': '70', 'type': 'subscript', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'dup'}; {'id': '72', 'type': 'slice', 'children': ['73', '74']}, {'id': '73', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '74', 'type': 'colon', 'children': []}, {'id': '75', 'type': 'block', 'children': ['76', '85', '104']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'nl'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'notify'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'binary_operator', 'children': ['83', '84'], 'value': '%'}, {'id': '83', 'type': 'string', 'children': [], 'value': "'\\tdeleting %s'"}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'each_dup'}, {'id': '85', 'type': 'try_statement', 'children': ['86', '94']}; {'id': '86', 'type': 'block', 'children': ['87']}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'each_dup'}; {'id': '94', 'type': 'except_clause', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'IOError'}; {'id': '96', 'type': 'block', 'children': ['97']}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'nl'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'notify'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'string', 'children': [], 'value': "'\\t[failed]'"}; {'id': '104', 'type': 'delete_statement', 'children': ['105']}, {'id': '105', 'type': 'parenthesized_expression', 'children': ['106'], 'value': '()'}; {'id': '106', 'type': 'subscript', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'files'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'each_dup'}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'clustered'}; {'id': '112', 'type': 'call', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'cluster_files'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'files'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'output_dir'}, {'id': '119', 'type': 'binary_operator', 'children': ['120', '121'], 'value': '%'}; {'id': '120', 'type': 'string', 'children': [], 'value': "'%s-sorted'"}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'orig_dir'}; {'id': '122', 'type': 'for_statement', 'children': ['123', '124', '125']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'clustered'}, {'id': '125', 'type': 'block', 'children': ['126', '166', '189', '225', '237', '246']}; {'id': '126', 'type': 'if_statement', 'children': ['127', '136']}, {'id': '127', 'type': 'comparison_operator', 'children': ['128', '131'], 'value': 'in'}; {'id': '128', 'type': 'tuple', 'children': ['129', '130']}, {'id': '129', 'type': 'integer', 'children': [], 'value': '0x8'}; {'id': '130', 'type': 'integer', 'children': [], 'value': '0x31'}, {'id': '131', 'type': 'subscript', 'children': ['132', '135']}; {'id': '132', 'type': 'subscript', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'clustered'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '135', 'type': 'string', 'children': [], 'value': "'info'"}; {'id': '136', 'type': 'block', 'children': ['137']}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '148']}, {'id': '139', 'type': 'subscript', 'children': ['140', '145']}; {'id': '140', 'type': 'subscript', 'children': ['141', '144']}, {'id': '141', 'type': 'subscript', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'clustered'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '144', 'type': 'string', 'children': [], 'value': "'info'"}, {'id': '145', 'type': 'tuple', 'children': ['146', '147']}; {'id': '146', 'type': 'integer', 'children': [], 'value': '0x8'}, {'id': '147', 'type': 'integer', 'children': [], 'value': '0x31'}; {'id': '148', 'type': 'call', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}, {'id': '151', 'type': 'call', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'call', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}, {'id': '157', 'type': 'subscript', 'children': ['158', '163']}; {'id': '158', 'type': 'subscript', 'children': ['159', '162']}, {'id': '159', 'type': 'subscript', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'clustered'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '162', 'type': 'string', 'children': [], 'value': "'info'"}, {'id': '163', 'type': 'tuple', 'children': ['164', '165']}; {'id': '164', 'type': 'integer', 'children': [], 'value': '0x8'}, {'id': '165', 'type': 'integer', 'children': [], 'value': '0x31'}; {'id': '166', 'type': 'for_statement', 'children': ['167', '168', '169']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'tags'}, {'id': '169', 'type': 'block', 'children': ['170']}; {'id': '170', 'type': 'if_statement', 'children': ['171', '178']}, {'id': '171', 'type': 'comparison_operator', 'children': ['172', '173'], 'value': 'not'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '173', 'type': 'subscript', 'children': ['174', '177']}; {'id': '174', 'type': 'subscript', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'clustered'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '177', 'type': 'string', 'children': [], 'value': "'info'"}; {'id': '178', 'type': 'block', 'children': ['179']}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '188']}, {'id': '181', 'type': 'subscript', 'children': ['182', '187']}; {'id': '182', 'type': 'subscript', 'children': ['183', '186']}, {'id': '183', 'type': 'subscript', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'clustered'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '186', 'type': 'string', 'children': [], 'value': "'info'"}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '188', 'type': 'string', 'children': [], 'value': "'_'"}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'run_name'}; {'id': '192', 'type': 'binary_operator', 'children': ['193', '215'], 'value': '+'}, {'id': '193', 'type': 'call', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'list_comprehension', 'children': ['199', '212']}, {'id': '199', 'type': 'call', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'scrub_fname'}, {'id': '201', 'type': 'argument_list', 'children': ['202']}; {'id': '202', 'type': 'call', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '204', 'type': 'argument_list', 'children': ['205']}, {'id': '205', 'type': 'subscript', 'children': ['206', '211']}; {'id': '206', 'type': 'subscript', 'children': ['207', '210']}, {'id': '207', 'type': 'subscript', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'clustered'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '210', 'type': 'string', 'children': [], 'value': "'info'"}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '212', 'type': 'for_in_clause', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'tags'}, {'id': '215', 'type': 'binary_operator', 'children': ['216', '217'], 'value': '%'}; {'id': '216', 'type': 'string', 'children': [], 'value': "'-%d_images'"}, {'id': '217', 'type': 'call', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '219', 'type': 'argument_list', 'children': ['220']}; {'id': '220', 'type': 'subscript', 'children': ['221', '224']}, {'id': '221', 'type': 'subscript', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'clustered'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '224', 'type': 'string', 'children': [], 'value': "'files'"}, {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'run_dir'}; {'id': '228', 'type': 'call', 'children': ['229', '234']}, {'id': '229', 'type': 'attribute', 'children': ['230', '233']}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '234', 'type': 'argument_list', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'run_name'}, {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'call', 'children': ['239', '242']}, {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'nl'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'notify'}; {'id': '242', 'type': 'argument_list', 'children': ['243']}, {'id': '243', 'type': 'binary_operator', 'children': ['244', '245'], 'value': '%'}; {'id': '244', 'type': 'string', 'children': [], 'value': "'Moving files into %s'"}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'run_dir'}; {'id': '246', 'type': 'try_statement', 'children': ['247', '266', '278']}, {'id': '247', 'type': 'block', 'children': ['248']}; {'id': '248', 'type': 'if_statement', 'children': ['249', '258']}, {'id': '249', 'type': 'not_operator', 'children': ['250']}; {'id': '250', 'type': 'call', 'children': ['251', '256']}, {'id': '251', 'type': 'attribute', 'children': ['252', '255']}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '256', 'type': 'argument_list', 'children': ['257']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'run_dir'}; {'id': '258', 'type': 'block', 'children': ['259']}, {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'call', 'children': ['261', '264']}, {'id': '261', 'type': 'attribute', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'makedirs'}; {'id': '264', 'type': 'argument_list', 'children': ['265']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'run_dir'}; {'id': '266', 'type': 'except_clause', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'IOError'}; {'id': '268', 'type': 'block', 'children': ['269']}, {'id': '269', 'type': 'expression_statement', 'children': ['270']}; {'id': '270', 'type': 'call', 'children': ['271', '274']}, {'id': '271', 'type': 'attribute', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'nl'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'notify'}; {'id': '274', 'type': 'argument_list', 'children': ['275']}, {'id': '275', 'type': 'binary_operator', 'children': ['276', '277'], 'value': '%'}; {'id': '276', 'type': 'string', 'children': [], 'value': "'Error: failed to create directory %s'"}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'run_dir'}; {'id': '278', 'type': 'else_clause', 'children': ['279']}, {'id': '279', 'type': 'block', 'children': ['280']}; {'id': '280', 'type': 'for_statement', 'children': ['281', '282', '287']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '282', 'type': 'subscript', 'children': ['283', '286']}, {'id': '283', 'type': 'subscript', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'clustered'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '286', 'type': 'string', 'children': [], 'value': "'files'"}, {'id': '287', 'type': 'block', 'children': ['288']}; {'id': '288', 'type': 'try_statement', 'children': ['289', '336']}, {'id': '289', 'type': 'block', 'children': ['290', '303', '320']}; {'id': '290', 'type': 'expression_statement', 'children': ['291']}, {'id': '291', 'type': 'assignment', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'dset_fname'}, {'id': '293', 'type': 'subscript', 'children': ['294', '302']}; {'id': '294', 'type': 'call', 'children': ['295', '300']}, {'id': '295', 'type': 'attribute', 'children': ['296', '299']}; {'id': '296', 'type': 'attribute', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '300', 'type': 'argument_list', 'children': ['301']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '302', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '303', 'type': 'if_statement', 'children': ['304', '309']}; {'id': '304', 'type': 'comparison_operator', 'children': ['305', '308'], 'value': '=='}, {'id': '305', 'type': 'subscript', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'dset_fname'}, {'id': '307', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '308', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '309', 'type': 'block', 'children': ['310']}; {'id': '310', 'type': 'expression_statement', 'children': ['311']}, {'id': '311', 'type': 'assignment', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'dset_fname'}, {'id': '313', 'type': 'binary_operator', 'children': ['314', '315'], 'value': '+'}; {'id': '314', 'type': 'string', 'children': [], 'value': "'_'"}, {'id': '315', 'type': 'subscript', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'dset_fname'}, {'id': '317', 'type': 'slice', 'children': ['318', '319']}; {'id': '318', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '319', 'type': 'colon', 'children': []}; {'id': '320', 'type': 'expression_statement', 'children': ['321']}, {'id': '321', 'type': 'call', 'children': ['322', '325']}; {'id': '322', 'type': 'attribute', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'rename'}, {'id': '325', 'type': 'argument_list', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '327', 'type': 'call', 'children': ['328', '333']}; {'id': '328', 'type': 'attribute', 'children': ['329', '332']}, {'id': '329', 'type': 'attribute', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '333', 'type': 'argument_list', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'run_dir'}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'dset_fname'}; {'id': '336', 'type': 'except_clause', 'children': ['337', '340']}, {'id': '337', 'type': 'tuple', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'IOError'}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'OSError'}; {'id': '340', 'type': 'block', 'children': ['341']}, {'id': '341', 'type': 'pass_statement', 'children': []}; {'id': '342', 'type': 'for_statement', 'children': ['343', '347', '356']}, {'id': '343', 'type': 'pattern_list', 'children': ['344', '345', '346']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'ds'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'fs'}, {'id': '347', 'type': 'call', 'children': ['348', '351']}; {'id': '348', 'type': 'attribute', 'children': ['349', '350']}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'walk'}, {'id': '351', 'type': 'argument_list', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'output_dir'}, {'id': '353', 'type': 'keyword_argument', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'topdown'}, {'id': '355', 'type': 'False', 'children': []}; {'id': '356', 'type': 'block', 'children': ['357']}, {'id': '357', 'type': 'for_statement', 'children': ['358', '359', '360']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'ds'}; {'id': '360', 'type': 'block', 'children': ['361', '373']}, {'id': '361', 'type': 'expression_statement', 'children': ['362']}; {'id': '362', 'type': 'assignment', 'children': ['363', '364']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'dname'}; {'id': '364', 'type': 'call', 'children': ['365', '370']}, {'id': '365', 'type': 'attribute', 'children': ['366', '369']}; {'id': '366', 'type': 'attribute', 'children': ['367', '368']}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '370', 'type': 'argument_list', 'children': ['371', '372']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '373', 'type': 'if_statement', 'children': ['374', '385']}; {'id': '374', 'type': 'comparison_operator', 'children': ['375', '384'], 'value': '=='}, {'id': '375', 'type': 'call', 'children': ['376', '377']}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '377', 'type': 'argument_list', 'children': ['378']}; {'id': '378', 'type': 'call', 'children': ['379', '382']}, {'id': '379', 'type': 'attribute', 'children': ['380', '381']}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'listdir'}; {'id': '382', 'type': 'argument_list', 'children': ['383']}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 'dname'}; {'id': '384', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '385', 'type': 'block', 'children': ['386']}; {'id': '386', 'type': 'expression_statement', 'children': ['387']}, {'id': '387', 'type': 'call', 'children': ['388', '391']}; {'id': '388', 'type': 'attribute', 'children': ['389', '390']}, {'id': '389', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'remove'}, {'id': '391', 'type': 'argument_list', 'children': ['392']}
def organize_dir(orig_dir): '''scans through the given directory and organizes DICOMs that look similar into subdirectories output directory is the ``orig_dir`` with ``-sorted`` appended to the end''' tags = [ (0x10,0x20), (0x8,0x21), (0x8,0x31), (0x8,0x103e) ] orig_dir = orig_dir.rstrip('/') files = scan_dir(orig_dir,tags=tags,md5_hash=True) dups = find_dups(files) for dup in dups: nl.notify('Found duplicates of %s...' % dup[0]) for each_dup in dup[1:]: nl.notify('\tdeleting %s' % each_dup) try: os.remove(each_dup) except IOError: nl.notify('\t[failed]') del(files[each_dup]) clustered = cluster_files(files) output_dir = '%s-sorted' % orig_dir for key in clustered: if (0x8,0x31) in clustered[key]['info']: clustered[key]['info'][(0x8,0x31)] = str(int(float(clustered[key]['info'][(0x8,0x31)]))) for t in tags: if t not in clustered[key]['info']: clustered[key]['info'][t] = '_' run_name = '-'.join([scrub_fname(str(clustered[key]['info'][x])) for x in tags])+'-%d_images' %len(clustered[key]['files']) run_dir = os.path.join(output_dir,run_name) nl.notify('Moving files into %s' % run_dir) try: if not os.path.exists(run_dir): os.makedirs(run_dir) except IOError: nl.notify('Error: failed to create directory %s' % run_dir) else: for f in clustered[key]['files']: try: dset_fname = os.path.split(f)[1] if dset_fname[0]=='.': dset_fname = '_' + dset_fname[1:] os.rename(f,os.path.join(run_dir,dset_fname)) except (IOError, OSError): pass for r,ds,fs in os.walk(output_dir,topdown=False): for d in ds: dname = os.path.join(r,d) if len(os.listdir(dname))==0: os.remove(dname)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'reconstruct_files'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'input_dir'}, {'id': '5', 'type': 'block', 'children': ['6', '8', '17']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'string', 'children': [], 'value': "'''sorts ``input_dir`` and tries to reconstruct the subdirectories found'''"}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'input_dir'}, {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'input_dir'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'rstrip'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '17', 'type': 'with_statement', 'children': ['18', '26']}; {'id': '18', 'type': 'with_clause', 'children': ['19']}, {'id': '19', 'type': 'with_item', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'nl'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'notify'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'string', 'children': [], 'value': "'Attempting to organize/reconstruct directory'"}; {'id': '26', 'type': 'block', 'children': ['27', '76', '85', '91']}, {'id': '27', 'type': 'for_statement', 'children': ['28', '32', '38']}; {'id': '28', 'type': 'pattern_list', 'children': ['29', '30', '31']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'ds'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'fs'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'walk'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'input_dir'}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'for_statement', 'children': ['40', '41', '42']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'fs'}; {'id': '42', 'type': 'block', 'children': ['43']}, {'id': '43', 'type': 'if_statement', 'children': ['44', '49']}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '48'], 'value': '=='}, {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '47', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '48', 'type': 'string', 'children': [], 'value': "'.'"}, {'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': 'shutil'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'move'}, {'id': '55', 'type': 'argument_list', 'children': ['56', '65']}; {'id': '56', 'type': 'call', 'children': ['57', '62']}, {'id': '57', 'type': 'attribute', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '65', 'type': 'call', 'children': ['66', '71']}; {'id': '66', 'type': 'attribute', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '71', 'type': 'argument_list', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '73', 'type': 'binary_operator', 'children': ['74', '75'], 'value': '+'}; {'id': '74', 'type': 'string', 'children': [], 'value': "'i'"}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'call', 'children': ['78', '83']}; {'id': '78', 'type': 'attribute', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'nl'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'dicom'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'organize_dir'}, {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'input_dir'}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '%'}, {'id': '89', 'type': 'string', 'children': [], 'value': "'%s-sorted'"}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'input_dir'}, {'id': '91', 'type': 'if_statement', 'children': ['92', '100', '141']}; {'id': '92', 'type': 'call', 'children': ['93', '98']}, {'id': '93', 'type': 'attribute', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '100', 'type': 'block', 'children': ['101']}, {'id': '101', 'type': 'with_statement', 'children': ['102', '110']}; {'id': '102', 'type': 'with_clause', 'children': ['103']}, {'id': '103', 'type': 'with_item', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'nl'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'run_in'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '110', 'type': 'block', 'children': ['111']}, {'id': '111', 'type': 'for_statement', 'children': ['112', '113', '119']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'dset_dir'}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'listdir'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '119', 'type': 'block', 'children': ['120']}; {'id': '120', 'type': 'with_statement', 'children': ['121', '131']}, {'id': '121', 'type': 'with_clause', 'children': ['122']}; {'id': '122', 'type': 'with_item', 'children': ['123']}, {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'nl'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'notify'}, {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'binary_operator', 'children': ['129', '130'], 'value': '%'}, {'id': '129', 'type': 'string', 'children': [], 'value': "'creating dataset from %s'"}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'dset_dir'}, {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'call', 'children': ['134', '139']}; {'id': '134', 'type': 'attribute', 'children': ['135', '138']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'nl'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'dicom'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'create_dset'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'dset_dir'}, {'id': '141', 'type': 'else_clause', 'children': ['142']}; {'id': '142', 'type': 'block', 'children': ['143']}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'call', 'children': ['145', '148']}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'nl'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'notify'}; {'id': '148', 'type': 'argument_list', 'children': ['149', '152']}, {'id': '149', 'type': 'binary_operator', 'children': ['150', '151'], 'value': '%'}; {'id': '150', 'type': 'string', 'children': [], 'value': "'Warning: failed to auto-organize directory %s'"}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'input_dir'}; {'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '154', 'type': 'attribute', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'nl'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'level'}
def reconstruct_files(input_dir): '''sorts ``input_dir`` and tries to reconstruct the subdirectories found''' input_dir = input_dir.rstrip('/') with nl.notify('Attempting to organize/reconstruct directory'): for r,ds,fs in os.walk(input_dir): for f in fs: if f[0]=='.': shutil.move(os.path.join(r,f),os.path.join(r,'i'+f)) nl.dicom.organize_dir(input_dir) output_dir = '%s-sorted' % input_dir if os.path.exists(output_dir): with nl.run_in(output_dir): for dset_dir in os.listdir('.'): with nl.notify('creating dataset from %s' % dset_dir): nl.dicom.create_dset(dset_dir) else: nl.notify('Warning: failed to auto-organize directory %s' % input_dir,level=nl.level.warning)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'lint'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'targets'}; {'id': '6', 'type': 'block', 'children': ['7', '13', '23', '45', '57', '67']}, {'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': 'LinterRunner'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'targets'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'targets'}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'linters'}; {'id': '16', 'type': 'call', 'children': ['17', '22']}, {'id': '17', 'type': 'attribute', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '_config'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'get_linter_classes'}; {'id': '22', 'type': 'argument_list', 'children': []}, {'id': '23', 'type': 'with_statement', 'children': ['24', '32']}; {'id': '24', 'type': 'with_clause', 'children': ['25']}, {'id': '25', 'type': 'with_item', 'children': ['26']}; {'id': '26', 'type': 'as_pattern', 'children': ['27', '30']}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'Pool'}, {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'as_pattern_target', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'pool'}; {'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': 'out_err_none'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'pool'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'LinterRunner'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'linters'}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'out_err'}; {'id': '48', 'type': 'list_comprehension', 'children': ['49', '50', '53']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '50', 'type': 'for_in_clause', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'out_err_none'}, {'id': '53', 'type': 'if_clause', 'children': ['54']}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'is'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '56', 'type': 'None', 'children': []}, {'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': 'stdout'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'list_splat', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'out_err'}, {'id': '67', 'type': 'return_statement', 'children': ['68']}; {'id': '68', 'type': 'expression_list', 'children': ['69', '78']}, {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'chain'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'from_iterable'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'chain'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'from_iterable'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'stderr'}
def lint(self, targets): LinterRunner.targets = targets linters = self._config.get_linter_classes() with Pool() as pool: out_err_none = pool.map(LinterRunner.run, linters) out_err = [item for item in out_err_none if item is not None] stdout, stderr = zip(*out_err) return sorted(chain.from_iterable(stdout)), chain.from_iterable(stderr)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_linear_interp'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'curve'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'test_x'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'round_result'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '14']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '13', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '14', 'type': 'for_statement', 'children': ['15', '16', '25', '146']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'binary_operator', 'children': ['20', '24'], 'value': '-'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'curve'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '25', 'type': 'block', 'children': ['26', '42']}; {'id': '26', 'type': 'if_statement', 'children': ['27', '40']}, {'id': '27', 'type': 'comparison_operator', 'children': ['28', '33'], 'value': '=='}; {'id': '28', 'type': 'subscript', 'children': ['29', '32']}, {'id': '29', 'type': 'subscript', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'curve'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '32', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '33', 'type': 'subscript', 'children': ['34', '39']}; {'id': '34', 'type': 'subscript', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'curve'}; {'id': '36', 'type': 'binary_operator', 'children': ['37', '38'], 'value': '+'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '39', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'continue_statement', 'children': []}; {'id': '42', 'type': 'if_statement', 'children': ['43', '57']}, {'id': '43', 'type': 'comparison_operator', 'children': ['44', '49', '50'], 'value': '<='}; {'id': '44', 'type': 'subscript', 'children': ['45', '48']}, {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'curve'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '48', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'test_x'}; {'id': '50', 'type': 'subscript', 'children': ['51', '56']}, {'id': '51', 'type': 'subscript', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'curve'}, {'id': '53', 'type': 'binary_operator', 'children': ['54', '55'], 'value': '+'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '55', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '56', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '57', 'type': 'block', 'children': ['58', '91', '108', '117']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'slope'}, {'id': '61', 'type': 'parenthesized_expression', 'children': ['62'], 'value': '()'}; {'id': '62', 'type': 'binary_operator', 'children': ['63', '77'], 'value': '/'}, {'id': '63', 'type': 'parenthesized_expression', 'children': ['64'], 'value': '()'}; {'id': '64', 'type': 'binary_operator', 'children': ['65', '72'], 'value': '-'}, {'id': '65', 'type': 'subscript', 'children': ['66', '71']}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'curve'}; {'id': '68', 'type': 'binary_operator', 'children': ['69', '70'], 'value': '+'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '70', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '71', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '72', 'type': 'subscript', 'children': ['73', '76']}, {'id': '73', 'type': 'subscript', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'curve'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '76', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '77', 'type': 'parenthesized_expression', 'children': ['78'], 'value': '()'}; {'id': '78', 'type': 'binary_operator', 'children': ['79', '86'], 'value': '-'}, {'id': '79', 'type': 'subscript', 'children': ['80', '85']}; {'id': '80', 'type': 'subscript', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'curve'}; {'id': '82', 'type': 'binary_operator', 'children': ['83', '84'], 'value': '+'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '84', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '85', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '86', 'type': 'subscript', 'children': ['87', '90']}, {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'curve'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'y_intercept'}; {'id': '94', 'type': 'binary_operator', 'children': ['95', '100'], 'value': '-'}, {'id': '95', 'type': 'subscript', 'children': ['96', '99']}; {'id': '96', 'type': 'subscript', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'curve'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '99', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '100', 'type': 'parenthesized_expression', 'children': ['101'], 'value': '()'}, {'id': '101', 'type': 'binary_operator', 'children': ['102', '103'], 'value': '*'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'slope'}, {'id': '103', 'type': 'subscript', 'children': ['104', '107']}; {'id': '104', 'type': 'subscript', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'curve'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '107', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '111', 'type': 'binary_operator', 'children': ['112', '116'], 'value': '+'}; {'id': '112', 'type': 'parenthesized_expression', 'children': ['113'], 'value': '()'}, {'id': '113', 'type': 'binary_operator', 'children': ['114', '115'], 'value': '*'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'slope'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'test_x'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'y_intercept'}, {'id': '117', 'type': 'if_statement', 'children': ['118', '119', '128']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'round_result'}, {'id': '119', 'type': 'block', 'children': ['120']}; {'id': '120', 'type': 'return_statement', 'children': ['121']}, {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'call', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'round'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '128', 'type': 'else_clause', 'children': ['129']}, {'id': '129', 'type': 'block', 'children': ['130']}; {'id': '130', 'type': 'if_statement', 'children': ['131', '136', '142']}, {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'is_integer'}, {'id': '135', 'type': 'argument_list', 'children': []}; {'id': '136', 'type': 'block', 'children': ['137']}, {'id': '137', 'type': 'return_statement', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '142', 'type': 'else_clause', 'children': ['143']}, {'id': '143', 'type': 'block', 'children': ['144']}; {'id': '144', 'type': 'return_statement', 'children': ['145']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '146', 'type': 'else_clause', 'children': ['147']}, {'id': '147', 'type': 'block', 'children': ['148']}; {'id': '148', 'type': 'raise_statement', 'children': ['149']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'ProbabilityUndefinedError'}
def _linear_interp(curve, test_x, round_result=False): index = 0 for index in range(len(curve) - 1): if curve[index][0] == curve[index + 1][0]: continue if curve[index][0] <= test_x <= curve[index + 1][0]: slope = ((curve[index + 1][1] - curve[index][1]) / (curve[index + 1][0] - curve[index][0])) y_intercept = curve[index][1] - (slope * curve[index][0]) result = (slope * test_x) + y_intercept if round_result: return int(round(result)) else: if result.is_integer(): return int(result) else: return result else: raise ProbabilityUndefinedError
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'bound_weights'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'weights'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'minimum'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'maximum'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '19', '92', '128', '166']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'bounded_weights'}, {'id': '15', 'type': 'subscript', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'weights'}, {'id': '17', 'type': 'slice', 'children': ['18']}; {'id': '18', 'type': 'colon', 'children': []}, {'id': '19', 'type': 'if_statement', 'children': ['20', '27', '50', '69', '88']}; {'id': '20', 'type': 'boolean_operator', 'children': ['21', '24'], 'value': 'and'}, {'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'is'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'minimum'}, {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'is'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'maximum'}; {'id': '26', 'type': 'None', 'children': []}, {'id': '27', 'type': 'block', 'children': ['28', '35']}; {'id': '28', 'type': 'if_statement', 'children': ['29', '32']}, {'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': '<'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'maximum'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'minimum'}; {'id': '32', 'type': 'block', 'children': ['33']}, {'id': '33', 'type': 'raise_statement', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'bounded_weights'}; {'id': '38', 'type': 'list_comprehension', 'children': ['39', '40', '43']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'bw'}; {'id': '40', 'type': 'for_in_clause', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'bw'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'bounded_weights'}, {'id': '43', 'type': 'if_clause', 'children': ['44']}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '46', '49'], 'value': '<='}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'minimum'}; {'id': '46', 'type': 'subscript', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'bw'}; {'id': '48', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'maximum'}; {'id': '50', 'type': 'elif_clause', 'children': ['51', '54']}, {'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'is'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'minimum'}, {'id': '53', 'type': 'None', 'children': []}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'bounded_weights'}; {'id': '58', 'type': 'list_comprehension', 'children': ['59', '60', '63']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'bw'}; {'id': '60', 'type': 'for_in_clause', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'bw'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'bounded_weights'}, {'id': '63', 'type': 'if_clause', 'children': ['64']}; {'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': '<='}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'minimum'}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'bw'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '69', 'type': 'elif_clause', 'children': ['70', '73']}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': 'is'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'maximum'}; {'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': 'bounded_weights'}, {'id': '77', 'type': 'list_comprehension', 'children': ['78', '79', '82']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'bw'}, {'id': '79', 'type': 'for_in_clause', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'bw'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'bounded_weights'}; {'id': '82', 'type': 'if_clause', 'children': ['83']}, {'id': '83', 'type': 'comparison_operator', 'children': ['84', '87'], 'value': '<='}; {'id': '84', 'type': 'subscript', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'bw'}; {'id': '86', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'maximum'}; {'id': '88', 'type': 'else_clause', 'children': ['89']}, {'id': '89', 'type': 'block', 'children': ['90']}; {'id': '90', 'type': 'return_statement', 'children': ['91']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'bounded_weights'}; {'id': '92', 'type': 'if_statement', 'children': ['93', '113']}, {'id': '93', 'type': 'parenthesized_expression', 'children': ['94'], 'value': '()'}; {'id': '94', 'type': 'boolean_operator', 'children': ['95', '106'], 'value': 'and'}, {'id': '95', 'type': 'comparison_operator', 'children': ['96', '101'], 'value': '>'}; {'id': '96', 'type': 'subscript', 'children': ['97', '100']}, {'id': '97', 'type': 'subscript', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'bounded_weights'}, {'id': '99', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '100', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '101', 'type': 'subscript', 'children': ['102', '105']}; {'id': '102', 'type': 'subscript', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'weights'}; {'id': '104', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '105', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '106', 'type': 'comparison_operator', 'children': ['107', '112'], 'value': '!='}, {'id': '107', 'type': 'subscript', 'children': ['108', '111']}; {'id': '108', 'type': 'subscript', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'bounded_weights'}; {'id': '110', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '111', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'minimum'}, {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'bounded_weights'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'insert'}, {'id': '119', 'type': 'argument_list', 'children': ['120', '121']}; {'id': '120', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '121', 'type': 'tuple', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'minimum'}, {'id': '123', 'type': 'call', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': '_linear_interp'}, {'id': '125', 'type': 'argument_list', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'weights'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'minimum'}; {'id': '128', 'type': 'if_statement', 'children': ['129', '152']}, {'id': '129', 'type': 'parenthesized_expression', 'children': ['130'], 'value': '()'}; {'id': '130', 'type': 'boolean_operator', 'children': ['131', '144'], 'value': 'and'}, {'id': '131', 'type': 'comparison_operator', 'children': ['132', '138'], 'value': '<'}; {'id': '132', 'type': 'subscript', 'children': ['133', '137']}, {'id': '133', 'type': 'subscript', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'bounded_weights'}, {'id': '135', 'type': 'unary_operator', 'children': ['136'], 'value': '-'}; {'id': '136', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '137', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '138', 'type': 'subscript', 'children': ['139', '143']}, {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'weights'}, {'id': '141', 'type': 'unary_operator', 'children': ['142'], 'value': '-'}; {'id': '142', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '143', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '144', 'type': 'comparison_operator', 'children': ['145', '151'], 'value': '!='}, {'id': '145', 'type': 'subscript', 'children': ['146', '150']}; {'id': '146', 'type': 'subscript', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'bounded_weights'}; {'id': '148', 'type': 'unary_operator', 'children': ['149'], 'value': '-'}, {'id': '149', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '150', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'maximum'}; {'id': '152', 'type': 'block', 'children': ['153']}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'call', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'bounded_weights'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}, {'id': '159', 'type': 'tuple', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'maximum'}, {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': '_linear_interp'}, {'id': '163', 'type': 'argument_list', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'weights'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'maximum'}; {'id': '166', 'type': 'return_statement', 'children': ['167']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'bounded_weights'}
def bound_weights(weights, minimum=None, maximum=None): bounded_weights = weights[:] if minimum is not None and maximum is not None: if maximum < minimum: raise ValueError bounded_weights = [bw for bw in bounded_weights if minimum <= bw[0] <= maximum] elif minimum is not None: bounded_weights = [bw for bw in bounded_weights if minimum <= bw[0]] elif maximum is not None: bounded_weights = [bw for bw in bounded_weights if bw[0] <= maximum] else: return bounded_weights if (bounded_weights[0][0] > weights[0][0] and bounded_weights[0][0] != minimum): bounded_weights.insert(0, (minimum, _linear_interp(weights, minimum))) if (bounded_weights[-1][0] < weights[-1][0] and bounded_weights[-1][0] != maximum): bounded_weights.append((maximum, _linear_interp(weights, maximum))) return bounded_weights
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'weighted_rand'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'weights'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'round_result'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '23', '38', '46', '55', '59', '72', '76']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '16']}; {'id': '10', 'type': 'comparison_operator', 'children': ['11', '15'], 'value': '=='}, {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'weights'}, {'id': '15', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'return_statement', 'children': ['18']}; {'id': '18', 'type': 'subscript', 'children': ['19', '22']}, {'id': '19', 'type': 'subscript', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'weights'}, {'id': '21', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '22', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'weights'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'weights'}; {'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '32', 'type': 'lambda', 'children': ['33', '35']}, {'id': '33', 'type': 'lambda_parameters', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'w'}, {'id': '35', 'type': 'subscript', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'w'}, {'id': '37', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'x_min'}, {'id': '41', 'type': 'subscript', 'children': ['42', '45']}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'weights'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '45', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'x_max'}, {'id': '49', 'type': 'subscript', 'children': ['50', '54']}; {'id': '50', 'type': 'subscript', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'weights'}; {'id': '52', 'type': 'unary_operator', 'children': ['53'], 'value': '-'}, {'id': '53', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '54', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'y_min'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'y_max'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'list_comprehension', 'children': ['66', '69']}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'point'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '69', 'type': 'for_in_clause', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'point'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'weights'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'attempt_count'}, {'id': '75', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '76', 'type': 'while_statement', 'children': ['77', '80', '129']}, {'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': '<'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'attempt_count'}, {'id': '79', 'type': 'integer', 'children': [], 'value': '500000'}; {'id': '80', 'type': 'block', 'children': ['81', '99', '125']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '84', 'type': 'tuple', 'children': ['85', '92']}, {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'random'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'uniform'}, {'id': '89', 'type': 'argument_list', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'x_min'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'x_max'}; {'id': '92', 'type': 'call', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'random'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'uniform'}; {'id': '96', 'type': 'argument_list', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'y_min'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'y_max'}, {'id': '99', 'type': 'if_statement', 'children': ['100', '105']}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': '_point_under_curve'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'weights'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'sample'}, {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'if_statement', 'children': ['107', '108', '119']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'round_result'}; {'id': '108', 'type': 'block', 'children': ['109']}, {'id': '109', 'type': 'return_statement', 'children': ['110']}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'round'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'subscript', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '118', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '119', 'type': 'else_clause', 'children': ['120']}; {'id': '120', 'type': 'block', 'children': ['121']}, {'id': '121', 'type': 'return_statement', 'children': ['122']}; {'id': '122', 'type': 'subscript', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '124', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'augmented_assignment', 'children': ['127', '128'], 'value': '+='}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'attempt_count'}; {'id': '128', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '129', 'type': 'else_clause', 'children': ['130']}; {'id': '130', 'type': 'block', 'children': ['131', '141']}, {'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': 'warnings'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}, {'id': '137', 'type': 'concatenated_string', 'children': ['138', '139', '140']}; {'id': '138', 'type': 'string', 'children': [], 'value': "'Point not being found in weighted_rand() after 500000 '"}, {'id': '139', 'type': 'string', 'children': [], 'value': "'attempts, defaulting to a random weight point. '"}; {'id': '140', 'type': 'string', 'children': [], 'value': "'If this happens often, it is probably a bug.'"}, {'id': '141', 'type': 'return_statement', 'children': ['142']}; {'id': '142', 'type': 'subscript', 'children': ['143', '149']}, {'id': '143', 'type': 'call', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'random'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'choice'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'weights'}, {'id': '149', 'type': 'integer', 'children': [], 'value': '0'}
def weighted_rand(weights, round_result=False): if len(weights) == 1: return weights[0][0] weights = sorted(weights, key=lambda w: w[0]) x_min = weights[0][0] x_max = weights[-1][0] y_min = 0 y_max = max([point[1] for point in weights]) attempt_count = 0 while attempt_count < 500000: sample = (random.uniform(x_min, x_max), random.uniform(y_min, y_max)) if _point_under_curve(weights, sample): if round_result: return int(round(sample[0])) else: return sample[0] attempt_count += 1 else: warnings.warn( 'Point not being found in weighted_rand() after 500000 ' 'attempts, defaulting to a random weight point. ' 'If this happens often, it is probably a bug.') return random.choice(weights)[0]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_cmp_key'}, {'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': 'obj'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '17', '31', '45']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '12']}; {'id': '10', 'type': 'not_operator', 'children': ['11']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'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': 'obj'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'line_nr'}; {'id': '20', 'type': 'conditional_expression', 'children': ['21', '27', '30'], 'value': 'if'}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'line_nr'}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'line_nr'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '34', 'type': 'conditional_expression', 'children': ['35', '41', '44'], 'value': 'if'}, {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'col'}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '45', 'type': 'return_statement', 'children': ['46']}; {'id': '46', 'type': 'tuple', 'children': ['47', '50', '51', '52']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'line_nr'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'obj'}
def _cmp_key(self, obj=None): if not obj: obj = self line_nr = int(obj.line_nr) if obj.line_nr else 0 col = int(obj.col) if obj.col else 0 return (obj.path, line_nr, col, obj.msg)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_create_output_from_match'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'match_result'}; {'id': '6', 'type': 'block', 'children': ['7', '13', '22']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'full_path'}; {'id': '10', 'type': 'subscript', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'match_result'}; {'id': '12', 'type': 'string', 'children': [], 'value': "'full_path'"}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': '_get_relative_path'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'full_path'}; {'id': '22', 'type': 'return_statement', 'children': ['23']}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'LinterOutput'}, {'id': '25', 'type': 'argument_list', 'children': ['26', '29', '30']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '30', 'type': 'subscript', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'match_result'}
def _create_output_from_match(self, match_result): full_path = match_result['full_path'] path = self._get_relative_path(full_path) return LinterOutput(self.name, path, match_result['msg'])
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_cached_filename'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'extention'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'settings_list'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '26']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'cached_name'}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'string', 'children': [], 'value': '"_"'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'list', 'children': ['20', '21'], 'value': '[filename, self.get_hash()]'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'get_hash'}, {'id': '25', 'type': 'argument_list', 'children': []}; {'id': '26', 'type': 'return_statement', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'string', 'children': [], 'value': '"."'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'list', 'children': ['33', '34'], 'value': '[cached_name, extention]'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'cached_name'}
def get_cached_filename(self, filename, extention, settings_list=None): cached_name = "_".join([filename, self.get_hash()]) return ".".join([cached_name, extention])
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_func'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'variant'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'VARIANT1'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'case_sensitive'}, {'id': '9', 'type': 'False', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11']}, {'id': '11', 'type': 'return_statement', 'children': ['12']}; {'id': '12', 'type': 'lambda', 'children': ['13', '15']}, {'id': '13', 'type': 'lambda_parameters', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'normalize'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '19', '22']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'variant'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'variant'}; {'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'case_sensitive'}
def sort_func(variant=VARIANT1, case_sensitive=False): return lambda x: normalize( x, variant=variant, case_sensitive=case_sensitive)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_notify_reader_writes'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'writeto'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '43']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'satisfied'}, {'id': '9', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '10', 'type': 'for_statement', 'children': ['11', '12', '13']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'writeto'}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'if_statement', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'readable'}; {'id': '18', 'type': 'block', 'children': ['19']}, {'id': '19', 'type': 'for_statement', 'children': ['20', '21', '24']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'reader'}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'readers'}; {'id': '24', 'type': 'block', 'children': ['25', '31']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'reader'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'notify_read_ready'}; {'id': '30', 'type': 'argument_list', 'children': []}, {'id': '31', 'type': 'if_statement', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'reader'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'satisfied'}, {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'satisfied'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'reader'}, {'id': '43', 'type': 'return_statement', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'Closure'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'satisfied'}
def _notify_reader_writes(writeto): satisfied = [] for var in writeto: if var.readable: for reader in var.readers: reader.notify_read_ready() if reader.satisfied: satisfied.append(reader) return Closure.sort(satisfied)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'getFilePathsWithExtensionsInDirectory'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dirTree'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'patterns'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '14', '63', '72']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'filePaths'}, {'id': '13', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '14', 'type': 'for_statement', 'children': ['15', '19', '25']}, {'id': '15', 'type': 'pattern_list', 'children': ['16', '17', '18']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'dirs'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'files'}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'walk'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'dirTree'}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'for_statement', 'children': ['27', '28', '29']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'filePath'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'files'}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'for_statement', 'children': ['31', '32', '33']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'patterns'}, {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'if_statement', 'children': ['35', '42']}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'fnmatch'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'fnmatch'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'filePath'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '42', 'type': 'block', 'children': ['43', '55', '62']}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'fullPath'}; {'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': 'os'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'filePath'}, {'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': 'filePaths'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'fullPath'}; {'id': '62', 'type': 'break_statement', 'children': []}, {'id': '63', 'type': 'if_statement', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '65', 'type': 'block', 'children': ['66']}; {'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': 'filePaths'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '71', 'type': 'argument_list', 'children': []}; {'id': '72', 'type': 'return_statement', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'filePaths'}
def getFilePathsWithExtensionsInDirectory(dirTree, patterns, sort=True): filePaths = [] for root, dirs, files in os.walk(dirTree): for filePath in files: for pattern in patterns: if fnmatch.fnmatch(filePath, pattern): fullPath = os.path.join(root, filePath) filePaths.append(fullPath) break if sort: filePaths.sort() return filePaths
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'shellsort'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'inlist'}, {'id': '5', 'type': 'block', 'children': ['6', '13', '22', '29', '35', '130']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'inlist'}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'svec'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'deepcopy'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'inlist'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'ivec'}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'gap'}; {'id': '32', 'type': 'binary_operator', 'children': ['33', '34'], 'value': '/'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '34', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '35', 'type': 'while_statement', 'children': ['36', '39']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': '>'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'gap'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '39', 'type': 'block', 'children': ['40', '124']}; {'id': '40', 'type': 'for_statement', 'children': ['41', '42', '47']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'gap'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'for_statement', 'children': ['49', '50', '60']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '56', '58']}, {'id': '53', 'type': 'binary_operator', 'children': ['54', '55'], 'value': '-'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'gap'}; {'id': '56', 'type': 'unary_operator', 'children': ['57'], 'value': '-'}, {'id': '57', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '58', 'type': 'unary_operator', 'children': ['59'], 'value': '-'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'gap'}; {'id': '60', 'type': 'block', 'children': ['61']}, {'id': '61', 'type': 'while_statement', 'children': ['62', '75']}; {'id': '62', 'type': 'boolean_operator', 'children': ['63', '66'], 'value': 'and'}, {'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': '>='}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '65', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '66', 'type': 'comparison_operator', 'children': ['67', '70'], 'value': '>'}, {'id': '67', 'type': 'subscript', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'svec'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '70', 'type': 'subscript', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'svec'}; {'id': '72', 'type': 'binary_operator', 'children': ['73', '74'], 'value': '+'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'gap'}, {'id': '75', 'type': 'block', 'children': ['76', '82', '92', '100', '106', '116']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'temp'}, {'id': '79', 'type': 'subscript', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'svec'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '87']}; {'id': '84', 'type': 'subscript', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'svec'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'svec'}, {'id': '89', 'type': 'binary_operator', 'children': ['90', '91'], 'value': '+'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'gap'}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '99']}; {'id': '94', 'type': 'subscript', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'svec'}; {'id': '96', 'type': 'binary_operator', 'children': ['97', '98'], 'value': '+'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'gap'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'itemp'}, {'id': '103', 'type': 'subscript', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'ivec'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '111']}; {'id': '108', 'type': 'subscript', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'ivec'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '111', 'type': 'subscript', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'ivec'}, {'id': '113', 'type': 'binary_operator', 'children': ['114', '115'], 'value': '+'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'gap'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '123']}; {'id': '118', 'type': 'subscript', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'ivec'}; {'id': '120', 'type': 'binary_operator', 'children': ['121', '122'], 'value': '+'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'gap'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'itemp'}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'gap'}, {'id': '127', 'type': 'binary_operator', 'children': ['128', '129'], 'value': '/'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'gap'}, {'id': '129', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '130', 'type': 'return_statement', 'children': ['131']}, {'id': '131', 'type': 'expression_list', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'svec'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'ivec'}
def shellsort(inlist): n = len(inlist) svec = copy.deepcopy(inlist) ivec = range(n) gap = n / 2 while gap > 0: for i in range(gap, n): for j in range(i - gap, -1, -gap): while j >= 0 and svec[j] > svec[j + gap]: temp = svec[j] svec[j] = svec[j + gap] svec[j + gap] = temp itemp = ivec[j] ivec[j] = ivec[j + gap] ivec[j + gap] = itemp gap = gap / 2 return svec, ivec
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'rankdata'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'inlist'}, {'id': '5', 'type': 'block', 'children': ['6', '13', '22', '26', '30', '37', '114']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'inlist'}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '18']}, {'id': '15', 'type': 'pattern_list', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'svec'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'ivec'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'shellsort'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'inlist'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'sumranks'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'dupcount'}, {'id': '29', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'newlist'}, {'id': '33', 'type': 'binary_operator', 'children': ['34', '36'], 'value': '*'}; {'id': '34', 'type': 'list', 'children': ['35'], 'value': '[0]'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '37', 'type': 'for_statement', 'children': ['38', '39', '43']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '43', 'type': 'block', 'children': ['44', '50', '56']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'sumranks'}, {'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '+'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'sumranks'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'dupcount'}, {'id': '53', 'type': 'binary_operator', 'children': ['54', '55'], 'value': '+'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'dupcount'}, {'id': '55', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '56', 'type': 'if_statement', 'children': ['57', '72']}, {'id': '57', 'type': 'boolean_operator', 'children': ['58', '63'], 'value': 'or'}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': '=='}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '60', 'type': 'binary_operator', 'children': ['61', '62'], 'value': '-'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '62', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '63', 'type': 'comparison_operator', 'children': ['64', '67'], 'value': '!='}; {'id': '64', 'type': 'subscript', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'svec'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '67', 'type': 'subscript', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'svec'}, {'id': '69', 'type': 'binary_operator', 'children': ['70', '71'], 'value': '+'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '71', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '72', 'type': 'block', 'children': ['73', '84', '106', '110']}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'averank'}; {'id': '76', 'type': 'binary_operator', 'children': ['77', '83'], 'value': '+'}, {'id': '77', 'type': 'binary_operator', 'children': ['78', '79'], 'value': '/'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'sumranks'}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'dupcount'}, {'id': '83', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '84', 'type': 'for_statement', 'children': ['85', '86', '97']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '94']}, {'id': '89', 'type': 'binary_operator', 'children': ['90', '93'], 'value': '+'}; {'id': '90', 'type': 'binary_operator', 'children': ['91', '92'], 'value': '-'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'dupcount'}, {'id': '93', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '+'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '105']}; {'id': '100', 'type': 'subscript', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'newlist'}; {'id': '102', 'type': 'subscript', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'ivec'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'averank'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'sumranks'}, {'id': '109', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'dupcount'}, {'id': '113', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '114', 'type': 'return_statement', 'children': ['115']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'newlist'}
def rankdata(inlist): n = len(inlist) svec, ivec = shellsort(inlist) sumranks = 0 dupcount = 0 newlist = [0] * n for i in range(n): sumranks = sumranks + i dupcount = dupcount + 1 if i == n - 1 or svec[i] != svec[i + 1]: averank = sumranks / float(dupcount) + 1 for j in range(i - dupcount + 1, i + 1): newlist[ivec[j]] = averank sumranks = 0 dupcount = 0 return newlist
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_json'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'keyword_separator', 'children': []}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'indent'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort_keys'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'return_statement', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'json'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'dumps'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '39', '42', '45']}, {'id': '19', 'type': 'dictionary_comprehension', 'children': ['20', '23', '35']}; {'id': '20', 'type': 'pair', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '23', 'type': 'for_in_clause', 'children': ['24', '27']}; {'id': '24', 'type': 'pattern_list', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '27', 'type': 'call', 'children': ['28', '34']}; {'id': '28', 'type': 'attribute', 'children': ['29', '33']}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '34', 'type': 'argument_list', 'children': []}, {'id': '35', 'type': 'if_clause', 'children': ['36']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'is'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '38', 'type': 'None', 'children': []}, {'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'indent'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'indent'}; {'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'sort_keys'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'sort_keys'}, {'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': '_try_dict'}
def to_json(self, *, indent=None, sort_keys = False): return json.dumps({k: v for k, v in dict(self).items() if v is not None}, indent=indent, sort_keys=sort_keys, default=self._try_dict)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_sort_field'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '6', 'type': 'block', 'children': ['7']}, {'id': '7', 'type': 'try_statement', 'children': ['8', '21']}; {'id': '8', 'type': 'block', 'children': ['9']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '18']}; {'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': 'model'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_meta'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'get_field'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '18', 'type': 'block', 'children': ['19']}, {'id': '19', 'type': 'return_statement', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '21', 'type': 'except_clause', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'FieldDoesNotExist'}, {'id': '23', 'type': 'block', 'children': ['24', '57']}; {'id': '24', 'type': 'if_statement', 'children': ['25', '30']}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'basestring'}; {'id': '30', 'type': 'block', 'children': ['31', '40']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38', '39']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '39', 'type': 'None', 'children': []}; {'id': '40', 'type': 'if_statement', 'children': ['41', '48']}, {'id': '41', 'type': 'boolean_operator', 'children': ['42', '43'], 'value': 'and'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '45', 'type': 'argument_list', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '47', 'type': 'string', 'children': [], 'value': "'sort_field'"}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'return_statement', 'children': ['50']}; {'id': '50', 'type': 'attribute', 'children': ['51', '56']}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'sort_field'}, {'id': '57', 'type': 'return_statement', 'children': ['58']}
def get_sort_field(attr, model): try: if model._meta.get_field(attr): return attr except FieldDoesNotExist: if isinstance(attr, basestring): val = getattr(model, attr, None) if val and hasattr(val, 'sort_field'): return getattr(model, attr).sort_field return None
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_query_paths'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'return_statement', 'children': ['7']}, {'id': '7', 'type': 'call', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '9', 'type': 'argument_list', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'reversed'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '15', 'type': 'generator_expression', 'children': ['16', '19']}; {'id': '16', 'type': 'subscript', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '18', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '19', 'type': 'for_in_clause', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '21', 'type': 'call', 'children': ['22', '29']}; {'id': '22', 'type': 'attribute', 'children': ['23', '28']}, {'id': '23', 'type': 'attribute', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'namespace'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'alias_to_query_paths'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}
def sorted_query_paths(self): return list(reversed(sorted(p[0] for p in self.namespace.alias_to_query_paths.get(self.name))))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_arguments'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'actions'}; {'id': '6', 'type': 'block', 'children': ['7', '22']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'actions'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'actions'}; {'id': '14', 'type': 'keyword_argument', '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': 'operator'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'attrgetter'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'string', 'children': [], 'value': "'option_strings'"}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'call', 'children': ['24', '31']}; {'id': '24', 'type': 'attribute', 'children': ['25', '30']}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'super'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'SortedHelpFormatter'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'add_arguments'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}
def add_arguments(self, actions): actions = sorted( actions, key=operator.attrgetter('option_strings')) super(SortedHelpFormatter, self).add_arguments(actions)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_iter_indented_subactions'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '6', 'type': 'block', 'children': ['7']}, {'id': '7', 'type': 'try_statement', 'children': ['8', '15', '19']}; {'id': '8', 'type': 'block', 'children': ['9']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'get_subactions'}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_get_subactions'}, {'id': '15', 'type': 'except_clause', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'pass_statement', 'children': []}, {'id': '19', 'type': 'else_clause', 'children': ['20']}; {'id': '20', 'type': 'block', 'children': ['21', '27', '67']}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': '_indent'}; {'id': '26', 'type': 'argument_list', 'children': []}, {'id': '27', 'type': 'if_statement', 'children': ['28', '35', '56']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'argparse'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': '_SubParsersAction'}, {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'for_statement', 'children': ['37', '38', '52']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'subaction'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '44']}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'get_subactions'}, {'id': '43', 'type': 'argument_list', 'children': []}; {'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '46', 'type': 'lambda', 'children': ['47', '49']}, {'id': '47', 'type': 'lambda_parameters', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'dest'}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'yield', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'subaction'}; {'id': '56', 'type': 'else_clause', 'children': ['57']}, {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'for_statement', 'children': ['59', '60', '63']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'subaction'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'get_subactions'}; {'id': '62', 'type': 'argument_list', 'children': []}, {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'yield', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'subaction'}, {'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': 'self'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': '_dedent'}
def _iter_indented_subactions(self, action): try: get_subactions = action._get_subactions except AttributeError: pass else: self._indent() if isinstance(action, argparse._SubParsersAction): for subaction in sorted( get_subactions(), key=lambda x: x.dest): yield subaction else: for subaction in get_subactions(): yield subaction self._dedent()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort2sql'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '6', 'type': 'block', 'children': ['7', '13']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '10']}; {'id': '8', 'type': 'not_operator', 'children': ['9']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '10', 'type': 'block', 'children': ['11']}, {'id': '11', 'type': 'return_statement', 'children': ['12']}; {'id': '12', 'type': 'string', 'children': [], 'value': '""'}, {'id': '13', 'type': 'return_statement', 'children': ['14']}; {'id': '14', 'type': 'binary_operator', 'children': ['15', '16'], 'value': '+'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'SQL_ORDERBY'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'sql_list'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'list_comprehension', 'children': ['20', '37']}; {'id': '20', 'type': 'binary_operator', 'children': ['21', '27'], 'value': '+'}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'quote_column'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '27', 'type': 'parenthesized_expression', 'children': ['28'], 'value': '()'}; {'id': '28', 'type': 'conditional_expression', 'children': ['29', '30', '36'], 'value': 'if'}, {'id': '29', 'type': 'string', 'children': [], 'value': '" DESC"'}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '34'], 'value': '=='}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'o'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '34', 'type': 'unary_operator', 'children': ['35'], 'value': '-'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '36', 'type': 'string', 'children': [], 'value': '""'}, {'id': '37', 'type': 'for_in_clause', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'o'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'sort'}
def _sort2sql(self, sort): if not sort: return "" return SQL_ORDERBY + sql_list([quote_column(o.field) + (" DESC" if o.sort == -1 else "") for o in sort])
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'optimize_batch'}, {'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': 'batchsize'}, {'id': '7', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'returns'}; {'id': '10', 'type': 'string', 'children': [], 'value': "'best'"}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'paralell'}, {'id': '13', 'type': 'True', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '27', '51', '88', '103']}, {'id': '15', 'type': 'if_statement', 'children': ['16', '21']}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'not'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'returns'}; {'id': '18', 'type': 'tuple', 'children': ['19', '20']}, {'id': '19', 'type': 'string', 'children': [], 'value': "'best'"}; {'id': '20', 'type': 'string', 'children': [], 'value': "'all'"}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'raise_statement', 'children': ['23']}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'string', 'children': [], 'value': '\'returns must be either "best" or "all"\''}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'starts'}; {'id': '30', 'type': 'list_comprehension', 'children': ['31', '45']}, {'id': '31', 'type': 'binary_operator', 'children': ['32', '44'], 'value': '*'}; {'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': 'np'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'random'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'rand'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'binary_operator', 'children': ['40', '43'], 'value': '*'}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '43', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '10'}, {'id': '45', 'type': 'for_in_clause', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'batchsize'}, {'id': '51', 'type': 'if_statement', 'children': ['52', '53', '76']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'paralell'}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'with_statement', 'children': ['55', '63']}, {'id': '55', 'type': 'with_clause', 'children': ['56']}; {'id': '56', 'type': 'with_item', 'children': ['57']}, {'id': '57', 'type': 'as_pattern', 'children': ['58', '61']}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'Pool'}; {'id': '60', 'type': 'argument_list', 'children': []}, {'id': '61', 'type': 'as_pattern_target', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'map'}, {'id': '71', 'type': 'argument_list', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'optimize'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'starts'}; {'id': '76', 'type': 'else_clause', 'children': ['77']}, {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'map'}, {'id': '83', 'type': 'argument_list', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'optimize'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'starts'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '93', 'type': 'argument_list', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '97', 'type': 'lambda', 'children': ['98', '100']}; {'id': '98', 'type': 'lambda_parameters', 'children': ['99']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'stress'}, {'id': '103', 'type': 'return_statement', 'children': ['104']}; {'id': '104', 'type': 'conditional_expression', 'children': ['105', '106', '109'], 'value': 'if'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '106', 'type': 'comparison_operator', 'children': ['107', '108'], 'value': '=='}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'returns'}; {'id': '108', 'type': 'string', 'children': [], 'value': "'all'"}, {'id': '109', 'type': 'subscript', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '111', 'type': 'integer', 'children': [], 'value': '0'}
def optimize_batch(self, batchsize=10, returns='best', paralell=True): if returns not in ('best', 'all'): raise ValueError('returns must be either "best" or "all"') starts = [np.random.rand(self.m * 2) * 10 for i in range(batchsize)] if paralell: with Pool() as p: results = p.map(self.optimize, starts) else: results = map(self.optimize, starts) results = sorted(results, key=lambda x: x.stress) return results if returns == 'all' else results[0]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_gewesten'}, {'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': 'sort'}, {'id': '7', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '8', 'type': 'block', 'children': ['9', '11', '81', '117', '128']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'string', 'children': [], 'value': "'''\n List all `gewesten` in Belgium.\n :param integer sort: What field to sort on.\n :rtype: A :class`list` of class: `Gewest`.\n '''"}, {'id': '11', 'type': 'function_definition', 'children': ['12', '13', '14']}; {'id': '12', 'type': 'function_name', 'children': [], 'value': 'creator'}, {'id': '13', 'type': 'parameters', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '26', '30', '65']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'crab_gateway_request'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '24', '25']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '24', 'type': 'string', 'children': [], 'value': "'ListGewesten'"}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '29', 'type': 'dictionary', 'children': []}; {'id': '30', 'type': 'for_statement', 'children': ['31', '32', '35']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'GewestItem'}, {'id': '35', 'type': 'block', 'children': ['36', '51']}; {'id': '36', 'type': 'if_statement', 'children': ['37', '42']}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '41'], 'value': 'not'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'GewestId'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '42', 'type': 'block', 'children': ['43']}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '50']}, {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'GewestId'}; {'id': '50', 'type': 'dictionary', 'children': []}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '62']}, {'id': '53', 'type': 'subscript', 'children': ['54', '59']}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'GewestId'}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'TaalCodeGewestNaam'}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'GewestNaam'}, {'id': '65', 'type': 'return_statement', 'children': ['66']}; {'id': '66', 'type': 'list_comprehension', 'children': ['67', '72']}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'Gewest'}, {'id': '69', 'type': 'argument_list', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '72', 'type': 'for_in_clause', 'children': ['73', '76']}, {'id': '73', 'type': 'pattern_list', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '80', 'type': 'argument_list', 'children': []}, {'id': '81', 'type': 'if_statement', 'children': ['82', '89', '109']}; {'id': '82', 'type': 'attribute', 'children': ['83', '88']}, {'id': '83', 'type': 'subscript', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'caches'}, {'id': '87', 'type': 'string', 'children': [], 'value': "'permanent'"}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'is_configured'}, {'id': '89', 'type': 'block', 'children': ['90', '95']}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93', '94']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '93', 'type': 'ERROR', 'children': []}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'ListGewesten'}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'gewesten'}; {'id': '98', 'type': 'call', 'children': ['99', '106']}, {'id': '99', 'type': 'attribute', 'children': ['100', '105']}; {'id': '100', 'type': 'subscript', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'caches'}; {'id': '104', 'type': 'string', 'children': [], 'value': "'permanent'"}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'get_or_create'}; {'id': '106', 'type': 'argument_list', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'creator'}, {'id': '109', 'type': 'else_clause', 'children': ['110']}; {'id': '110', 'type': 'block', 'children': ['111']}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'gewesten'}; {'id': '114', 'type': 'call', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'creator'}; {'id': '116', 'type': 'argument_list', 'children': []}, {'id': '117', 'type': 'for_statement', 'children': ['118', '119', '120']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'g'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'gewesten'}; {'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': 'g'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'set_gateway'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '128', 'type': 'return_statement', 'children': ['129']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'gewesten'}
def list_gewesten(self, sort=1): ''' List all `gewesten` in Belgium. :param integer sort: What field to sort on. :rtype: A :class`list` of class: `Gewest`. ''' def creator(): res = crab_gateway_request(self.client, 'ListGewesten', sort) tmp = {} for r in res.GewestItem: if r.GewestId not in tmp: tmp[r.GewestId] = {} tmp[r.GewestId][r.TaalCodeGewestNaam] = r.GewestNaam return[ Gewest( k, v )for k, v in tmp.items() ] if self.caches['permanent'].is_configured: key = 'ListGewesten gewesten = self.caches['permanent'].get_or_create(key, creator) else: gewesten = creator() for g in gewesten: g.set_gateway(self) return gewesten
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_provincies'}, {'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': 'gewest'}, {'id': '7', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '8', 'type': 'block', 'children': ['9', '11', '26', '58', '94', '105']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'string', 'children': [], 'value': "'''\n List all `provincies` in a `gewest`.\n :param gewest: The :class:`Gewest` for which the \\\n `provincies` are wanted.\n :param integer sort: What field to sort on.\n :rtype: A :class:`list` of :class:`Provincie`.\n '''"}, {'id': '11', 'type': 'try_statement', 'children': ['12', '19']}; {'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': 'gewest_id'}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'gewest'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '19', 'type': 'except_clause', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'gewest_id'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'gewest'}; {'id': '26', 'type': 'function_definition', 'children': ['27', '28', '29']}, {'id': '27', 'type': 'function_name', 'children': [], 'value': 'creator'}; {'id': '28', 'type': 'parameters', 'children': []}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'return_statement', 'children': ['31']}, {'id': '31', 'type': 'list_comprehension', 'children': ['32', '47', '52']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'Provincie'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '38', '41']}, {'id': '35', 'type': 'subscript', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '37', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '40', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'Gewest'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'subscript', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '46', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '47', 'type': 'for_in_clause', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'provincies'}; {'id': '52', 'type': 'if_clause', 'children': ['53']}, {'id': '53', 'type': 'comparison_operator', 'children': ['54', '57'], 'value': '=='}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '56', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'gewest_id'}; {'id': '58', 'type': 'if_statement', 'children': ['59', '66', '86']}, {'id': '59', 'type': 'attribute', 'children': ['60', '65']}; {'id': '60', 'type': 'subscript', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'caches'}; {'id': '64', 'type': 'string', 'children': [], 'value': "'permanent'"}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'is_configured'}; {'id': '66', 'type': 'block', 'children': ['67', '72']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70', '71']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '70', 'type': 'ERROR', 'children': []}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'ListProvinciesByGewestId'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'provincies'}, {'id': '75', 'type': 'call', 'children': ['76', '83']}; {'id': '76', 'type': 'attribute', 'children': ['77', '82']}, {'id': '77', 'type': 'subscript', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'caches'}, {'id': '81', 'type': 'string', 'children': [], 'value': "'permanent'"}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'get_or_create'}, {'id': '83', 'type': 'argument_list', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'creator'}; {'id': '86', 'type': 'else_clause', 'children': ['87']}, {'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': 'provincies'}, {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'creator'}, {'id': '93', 'type': 'argument_list', 'children': []}; {'id': '94', 'type': 'for_statement', 'children': ['95', '96', '97']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'provincies'}, {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'set_gateway'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '105', 'type': 'return_statement', 'children': ['106']}
def list_provincies(self, gewest=2): ''' List all `provincies` in a `gewest`. :param gewest: The :class:`Gewest` for which the \ `provincies` are wanted. :param integer sort: What field to sort on. :rtype: A :class:`list` of :class:`Provincie`. ''' try: gewest_id = gewest.id except AttributeError: gewest_id = gewest def creator(): return [Provincie(p[0], p[1], Gewest(p[2])) for p in self.provincies if p[2] == gewest_id] if self.caches['permanent'].is_configured: key = 'ListProvinciesByGewestId provincies = self.caches['permanent'].get_or_create(key, creator) else: provincies = creator() for p in provincies: p.set_gateway(self) return provincies
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_gemeenten'}, {'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': 'gewest'}, {'id': '7', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '11', 'type': 'block', 'children': ['12', '14', '38', '44', '88', '124', '135']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'string', 'children': [], 'value': "'''\n List all `gemeenten` in a `gewest`.\n :param gewest: The :class:`Gewest` for which the \\\n `gemeenten` are wanted.\n :param integer sort: What field to sort on.\n :rtype: A :class:`list` of :class:`Gemeente`.\n '''"}; {'id': '14', 'type': 'try_statement', 'children': ['15', '22']}, {'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': 'gewest_id'}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'gewest'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '22', 'type': 'except_clause', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '24', 'type': 'block', 'children': ['25', '29']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'gewest_id'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'gewest'}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'gewest'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'get_gewest_by_id'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'gewest_id'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'gewest'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'clear_gateway'}, {'id': '43', 'type': 'argument_list', 'children': []}; {'id': '44', 'type': 'function_definition', 'children': ['45', '46', '47']}, {'id': '45', 'type': 'function_name', 'children': [], 'value': 'creator'}; {'id': '46', 'type': 'parameters', 'children': []}, {'id': '47', 'type': 'block', 'children': ['48', '60']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'crab_gateway_request'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '57', '58', '59']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'client'}, {'id': '57', 'type': 'string', 'children': [], 'value': "'ListGemeentenByGewestId'"}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'gewest_id'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '60', 'type': 'return_statement', 'children': ['61']}, {'id': '61', 'type': 'list_comprehension', 'children': ['62', '75', '80']}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'Gemeente'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '68', '71', '74']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'GemeenteId'}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'GemeenteNaam'}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'NISGemeenteCode'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'gewest'}, {'id': '75', 'type': 'for_in_clause', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'GemeenteItem'}; {'id': '80', 'type': 'if_clause', 'children': ['81']}, {'id': '81', 'type': 'comparison_operator', 'children': ['82', '85'], 'value': '=='}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'TaalCode'}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'TaalCodeGemeenteNaam'}; {'id': '88', 'type': 'if_statement', 'children': ['89', '96', '116']}, {'id': '89', 'type': 'attribute', 'children': ['90', '95']}; {'id': '90', 'type': 'subscript', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'caches'}; {'id': '94', 'type': 'string', 'children': [], 'value': "'permanent'"}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'is_configured'}; {'id': '96', 'type': 'block', 'children': ['97', '102']}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100', '101']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '100', 'type': 'ERROR', 'children': []}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'ListGemeentenByGewestId'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'gemeenten'}, {'id': '105', 'type': 'call', 'children': ['106', '113']}; {'id': '106', 'type': 'attribute', 'children': ['107', '112']}, {'id': '107', 'type': 'subscript', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'caches'}, {'id': '111', 'type': 'string', 'children': [], 'value': "'permanent'"}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'get_or_create'}, {'id': '113', 'type': 'argument_list', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'creator'}; {'id': '116', 'type': 'else_clause', 'children': ['117']}, {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'gemeenten'}, {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'creator'}, {'id': '123', 'type': 'argument_list', 'children': []}; {'id': '124', 'type': 'for_statement', 'children': ['125', '126', '127']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'gemeenten'}, {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'call', 'children': ['130', '133']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'set_gateway'}, {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '135', 'type': 'return_statement', 'children': ['136']}
def list_gemeenten(self, gewest=2, sort=1): ''' List all `gemeenten` in a `gewest`. :param gewest: The :class:`Gewest` for which the \ `gemeenten` are wanted. :param integer sort: What field to sort on. :rtype: A :class:`list` of :class:`Gemeente`. ''' try: gewest_id = gewest.id except AttributeError: gewest_id = gewest gewest = self.get_gewest_by_id(gewest_id) gewest.clear_gateway() def creator(): res = crab_gateway_request( self.client, 'ListGemeentenByGewestId', gewest_id, sort ) return[ Gemeente( r.GemeenteId, r.GemeenteNaam, r.NISGemeenteCode, gewest )for r in res.GemeenteItem if r.TaalCode == r.TaalCodeGemeenteNaam ] if self.caches['permanent'].is_configured: key = 'ListGemeentenByGewestId gemeenten = self.caches['permanent'].get_or_create(key, creator) else: gemeenten = creator() for g in gemeenten: g.set_gateway(self) return gemeenten
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_gemeenten'}, {'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': 'sort'}, {'id': '7', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '8', 'type': 'block', 'children': ['9', '11', '67', '103', '114']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'string', 'children': [], 'value': "'''\n List all `gemeenten` in Vlaanderen.\n :param integer sort: What field to sort on.\n :rtype: A :class:`list` of :class:`Gemeente`.\n '''"}, {'id': '11', 'type': 'function_definition', 'children': ['12', '13', '14']}; {'id': '12', 'type': 'function_name', 'children': [], 'value': 'creator'}, {'id': '13', 'type': 'parameters', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '23', '29', '38', '51']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '18', 'type': 'binary_operator', 'children': ['19', '22'], 'value': '+'}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'base_url'}; {'id': '22', 'type': 'string', 'children': [], 'value': "'/municipality'"}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'base_headers'}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '32', 'type': 'dictionary', 'children': ['33']}, {'id': '33', 'type': 'pair', 'children': ['34', '35']}; {'id': '34', 'type': 'string', 'children': [], 'value': "'orderbyCode'"}, {'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': '=='}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '37', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '41', 'type': 'call', 'children': ['42', '50']}; {'id': '42', 'type': 'attribute', 'children': ['43', '49']}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'capakey_rest_gateway_request'}, {'id': '45', 'type': 'argument_list', 'children': ['46', '47', '48']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '50', 'type': 'argument_list', 'children': []}, {'id': '51', 'type': 'return_statement', 'children': ['52']}; {'id': '52', 'type': 'list_comprehension', 'children': ['53', '62']}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'Gemeente'}, {'id': '55', 'type': 'argument_list', 'children': ['56', '59']}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '58', 'type': 'string', 'children': [], 'value': "'municipalityCode'"}, {'id': '59', 'type': 'subscript', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '61', 'type': 'string', 'children': [], 'value': "'municipalityName'"}; {'id': '62', 'type': 'for_in_clause', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '64', 'type': 'subscript', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '66', 'type': 'string', 'children': [], 'value': "'municipalities'"}, {'id': '67', 'type': 'if_statement', 'children': ['68', '75', '95']}; {'id': '68', 'type': 'attribute', 'children': ['69', '74']}, {'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': 'caches'}, {'id': '73', 'type': 'string', 'children': [], 'value': "'permanent'"}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'is_configured'}, {'id': '75', 'type': 'block', 'children': ['76', '81']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79', '80']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '79', 'type': 'ERROR', 'children': []}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'list_gemeenten_rest'}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'gemeente'}; {'id': '84', 'type': 'call', 'children': ['85', '92']}, {'id': '85', 'type': 'attribute', 'children': ['86', '91']}; {'id': '86', 'type': 'subscript', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'caches'}; {'id': '90', 'type': 'string', 'children': [], 'value': "'permanent'"}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'get_or_create'}; {'id': '92', 'type': 'argument_list', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'creator'}, {'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', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'gemeente'}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'creator'}; {'id': '102', 'type': 'argument_list', 'children': []}, {'id': '103', 'type': 'for_statement', 'children': ['104', '105', '106']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'g'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'gemeente'}; {'id': '106', 'type': 'block', 'children': ['107']}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'call', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'g'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'set_gateway'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '114', 'type': 'return_statement', 'children': ['115']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'gemeente'}
def list_gemeenten(self, sort=1): ''' List all `gemeenten` in Vlaanderen. :param integer sort: What field to sort on. :rtype: A :class:`list` of :class:`Gemeente`. ''' def creator(): url = self.base_url + '/municipality' h = self.base_headers p = { 'orderbyCode': sort == 1 } res = capakey_rest_gateway_request(url, h, p).json() return [ Gemeente(r['municipalityCode'], r['municipalityName']) for r in res['municipalities'] ] if self.caches['permanent'].is_configured: key = 'list_gemeenten_rest gemeente = self.caches['permanent'].get_or_create(key, creator) else: gemeente = creator() for g in gemeente: g.set_gateway(self) return gemeente
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_kadastrale_afdelingen'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '8', '39', '74']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'string', 'children': [], 'value': "'''\n List all `kadastrale afdelingen` in Flanders.\n :param integer sort: Field to sort on.\n :rtype: A :class:`list` of :class:`Afdeling`.\n '''"}; {'id': '8', 'type': 'function_definition', 'children': ['9', '10', '11']}, {'id': '9', 'type': 'function_name', 'children': [], 'value': 'creator'}; {'id': '10', 'type': 'parameters', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '20', '24', '37']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'gemeentes'}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'list_gemeenten'}, {'id': '19', 'type': 'argument_list', 'children': []}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '23', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '24', 'type': 'for_statement', 'children': ['25', '26', '27']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'gemeentes'}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'augmented_assignment', 'children': ['30', '31'], 'value': '+='}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'list_kadastrale_afdelingen_by_gemeente'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'g'}, {'id': '37', 'type': 'return_statement', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '39', 'type': 'if_statement', 'children': ['40', '47', '66']}; {'id': '40', 'type': 'attribute', 'children': ['41', '46']}, {'id': '41', 'type': 'subscript', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'caches'}, {'id': '45', 'type': 'string', 'children': [], 'value': "'permanent'"}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'is_configured'}, {'id': '47', 'type': 'block', 'children': ['48', '52']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '51', 'type': 'string', 'children': [], 'value': "'list_afdelingen_rest'"}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'afdelingen'}, {'id': '55', 'type': 'call', 'children': ['56', '63']}; {'id': '56', 'type': 'attribute', 'children': ['57', '62']}, {'id': '57', 'type': 'subscript', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'caches'}, {'id': '61', 'type': 'string', 'children': [], 'value': "'permanent'"}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'get_or_create'}, {'id': '63', 'type': 'argument_list', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'creator'}; {'id': '66', 'type': 'else_clause', 'children': ['67']}, {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'afdelingen'}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'creator'}, {'id': '73', 'type': 'argument_list', 'children': []}; {'id': '74', 'type': 'return_statement', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'afdelingen'}
def list_kadastrale_afdelingen(self): ''' List all `kadastrale afdelingen` in Flanders. :param integer sort: Field to sort on. :rtype: A :class:`list` of :class:`Afdeling`. ''' def creator(): gemeentes = self.list_gemeenten() res = [] for g in gemeentes: res += self.list_kadastrale_afdelingen_by_gemeente(g) return res if self.caches['permanent'].is_configured: key = 'list_afdelingen_rest' afdelingen = self.caches['permanent'].get_or_create(key, creator) else: afdelingen = creator() return afdelingen
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_kadastrale_afdelingen_by_gemeente'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'gemeente'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '9', 'type': 'block', 'children': ['10', '12', '36', '42', '107', '143', '154']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'string', 'children': [], 'value': "'''\n List all `kadastrale afdelingen` in a `gemeente`.\n :param gemeente: The :class:`Gemeente` for which the \\\n `afdelingen` are wanted.\n :param integer sort: Field to sort on.\n :rtype: A :class:`list` of :class:`Afdeling`.\n '''"}; {'id': '12', 'type': 'try_statement', 'children': ['13', '20']}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'gid'}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'gemeente'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '20', 'type': 'except_clause', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '22', 'type': 'block', 'children': ['23', '27']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'gid'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'gemeente'}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'gemeente'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'get_gemeente_by_id'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'gid'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'gemeente'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'clear_gateway'}, {'id': '41', 'type': 'argument_list', 'children': []}; {'id': '42', 'type': 'function_definition', 'children': ['43', '44', '45']}, {'id': '43', 'type': 'function_name', 'children': [], 'value': 'creator'}; {'id': '44', 'type': 'parameters', 'children': []}, {'id': '45', 'type': 'block', 'children': ['46', '56', '62', '71', '84']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '49', 'type': 'binary_operator', 'children': ['50', '53'], 'value': '+'}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'base_url'}, {'id': '53', 'type': 'binary_operator', 'children': ['54', '55'], 'value': '%'}; {'id': '54', 'type': 'string', 'children': [], 'value': "'/municipality/%s/department'"}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'gid'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'h'}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'base_headers'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '65', 'type': 'dictionary', 'children': ['66']}; {'id': '66', 'type': 'pair', 'children': ['67', '68']}, {'id': '67', 'type': 'string', 'children': [], 'value': "'orderbyCode'"}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': '=='}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '70', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '74', 'type': 'call', 'children': ['75', '83']}, {'id': '75', 'type': 'attribute', 'children': ['76', '82']}; {'id': '76', 'type': 'call', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'capakey_rest_gateway_request'}; {'id': '78', 'type': 'argument_list', 'children': ['79', '80', '81']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'h'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'json'}, {'id': '83', 'type': 'argument_list', 'children': []}; {'id': '84', 'type': 'return_statement', 'children': ['85']}, {'id': '85', 'type': 'list_comprehension', 'children': ['86', '102']}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'Afdeling'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '94', '99']}, {'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '91', 'type': 'subscript', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '93', 'type': 'string', 'children': [], 'value': "'departmentCode'"}; {'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'naam'}; {'id': '96', 'type': 'subscript', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '98', 'type': 'string', 'children': [], 'value': "'departmentName'"}, {'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'gemeente'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'gemeente'}; {'id': '102', 'type': 'for_in_clause', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '104', 'type': 'subscript', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '106', 'type': 'string', 'children': [], 'value': "'departments'"}, {'id': '107', 'type': 'if_statement', 'children': ['108', '115', '135']}; {'id': '108', 'type': 'attribute', 'children': ['109', '114']}, {'id': '109', 'type': 'subscript', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'caches'}, {'id': '113', 'type': 'string', 'children': [], 'value': "'permanent'"}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'is_configured'}, {'id': '115', 'type': 'block', 'children': ['116', '121']}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '119', '120']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '119', 'type': 'ERROR', 'children': []}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'list_kadastrale_afdelingen_by_gemeente_rest'}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'afdelingen'}; {'id': '124', 'type': 'call', 'children': ['125', '132']}, {'id': '125', 'type': 'attribute', 'children': ['126', '131']}; {'id': '126', 'type': 'subscript', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'caches'}; {'id': '130', 'type': 'string', 'children': [], 'value': "'permanent'"}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'get_or_create'}; {'id': '132', 'type': 'argument_list', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'creator'}, {'id': '135', 'type': 'else_clause', 'children': ['136']}; {'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': 'afdelingen'}; {'id': '140', 'type': 'call', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'creator'}; {'id': '142', 'type': 'argument_list', 'children': []}, {'id': '143', 'type': 'for_statement', 'children': ['144', '145', '146']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'afdelingen'}; {'id': '146', 'type': 'block', 'children': ['147']}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'call', 'children': ['149', '152']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'set_gateway'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '154', 'type': 'return_statement', 'children': ['155']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'afdelingen'}
def list_kadastrale_afdelingen_by_gemeente(self, gemeente, sort=1): ''' List all `kadastrale afdelingen` in a `gemeente`. :param gemeente: The :class:`Gemeente` for which the \ `afdelingen` are wanted. :param integer sort: Field to sort on. :rtype: A :class:`list` of :class:`Afdeling`. ''' try: gid = gemeente.id except AttributeError: gid = gemeente gemeente = self.get_gemeente_by_id(gid) gemeente.clear_gateway() def creator(): url = self.base_url + '/municipality/%s/department' % gid h = self.base_headers p = { 'orderbyCode': sort == 1 } res = capakey_rest_gateway_request(url, h, p).json() return [ Afdeling( id=r['departmentCode'], naam=r['departmentName'], gemeente=gemeente ) for r in res['departments']] if self.caches['permanent'].is_configured: key = 'list_kadastrale_afdelingen_by_gemeente_rest afdelingen = self.caches['permanent'].get_or_create(key, creator) else: afdelingen = creator() for a in afdelingen: a.set_gateway(self) return afdelingen
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_percelen_by_sectie'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sectie'}; {'id': '6', 'type': 'block', 'children': ['7', '9', '15', '23', '33', '39', '107', '143', '154']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'string', 'children': [], 'value': "'''\n List all percelen in a `sectie`.\n :param sectie: The :class:`Sectie` for which the percelen are wanted.\n :param integer sort: Field to sort on.\n :rtype: A :class:`list` of :class:`Perceel`.\n '''"}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sid'}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sectie'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'aid'}; {'id': '18', 'type': 'attribute', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'sectie'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'afdeling'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'gid'}; {'id': '26', 'type': 'attribute', 'children': ['27', '32']}, {'id': '27', 'type': 'attribute', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'sectie'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'afdeling'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'gemeente'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'id'}, {'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': 'sectie'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'clear_gateway'}; {'id': '38', 'type': 'argument_list', 'children': []}, {'id': '39', 'type': 'function_definition', 'children': ['40', '41', '42']}; {'id': '40', 'type': 'function_name', 'children': [], 'value': 'creator'}, {'id': '41', 'type': 'parameters', 'children': []}; {'id': '42', 'type': 'block', 'children': ['43', '56', '62', '69', '82']}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '46', 'type': 'binary_operator', 'children': ['47', '50'], 'value': '+'}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'base_url'}; {'id': '50', 'type': 'binary_operator', 'children': ['51', '52'], 'value': '%'}, {'id': '51', 'type': 'string', 'children': [], 'value': "'/municipality/%s/department/%s/section/%s/parcel'"}; {'id': '52', 'type': 'tuple', 'children': ['53', '54', '55']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'gid'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'aid'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'sid'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'h'}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'base_headers'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '65', 'type': 'dictionary', 'children': ['66']}; {'id': '66', 'type': 'pair', 'children': ['67', '68']}, {'id': '67', 'type': 'string', 'children': [], 'value': "'data'"}; {'id': '68', 'type': 'string', 'children': [], 'value': "'adp'"}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '72', 'type': 'call', 'children': ['73', '81']}, {'id': '73', 'type': 'attribute', 'children': ['74', '80']}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'capakey_rest_gateway_request'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '78', '79']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'h'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'json'}, {'id': '81', 'type': 'argument_list', 'children': []}; {'id': '82', 'type': 'return_statement', 'children': ['83']}, {'id': '83', 'type': 'list_comprehension', 'children': ['84', '102']}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'Perceel'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '90', '91', '94']}, {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '89', 'type': 'string', 'children': [], 'value': "'perceelnummer'"}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'sectie'}, {'id': '91', 'type': 'subscript', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '93', 'type': 'string', 'children': [], 'value': "'capakey'"}; {'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': 'parse_percid'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'subscript', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '101', 'type': 'string', 'children': [], 'value': "'capakey'"}; {'id': '102', 'type': 'for_in_clause', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '104', 'type': 'subscript', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '106', 'type': 'string', 'children': [], 'value': "'parcels'"}, {'id': '107', 'type': 'if_statement', 'children': ['108', '115', '135']}; {'id': '108', 'type': 'attribute', 'children': ['109', '114']}, {'id': '109', 'type': 'subscript', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'caches'}, {'id': '113', 'type': 'string', 'children': [], 'value': "'short'"}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'is_configured'}, {'id': '115', 'type': 'block', 'children': ['116', '121']}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '119', '120']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '119', 'type': 'ERROR', 'children': []}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'list_percelen_by_sectie_rest'}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'percelen'}; {'id': '124', 'type': 'call', 'children': ['125', '132']}, {'id': '125', 'type': 'attribute', 'children': ['126', '131']}; {'id': '126', 'type': 'subscript', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'caches'}; {'id': '130', 'type': 'string', 'children': [], 'value': "'short'"}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'get_or_create'}; {'id': '132', 'type': 'argument_list', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'creator'}, {'id': '135', 'type': 'else_clause', 'children': ['136']}; {'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': 'percelen'}; {'id': '140', 'type': 'call', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'creator'}; {'id': '142', 'type': 'argument_list', 'children': []}, {'id': '143', 'type': 'for_statement', 'children': ['144', '145', '146']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'percelen'}; {'id': '146', 'type': 'block', 'children': ['147']}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'call', 'children': ['149', '152']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'set_gateway'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '154', 'type': 'return_statement', 'children': ['155']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'percelen'}
def list_percelen_by_sectie(self, sectie): ''' List all percelen in a `sectie`. :param sectie: The :class:`Sectie` for which the percelen are wanted. :param integer sort: Field to sort on. :rtype: A :class:`list` of :class:`Perceel`. ''' sid = sectie.id aid = sectie.afdeling.id gid = sectie.afdeling.gemeente.id sectie.clear_gateway() def creator(): url = self.base_url + '/municipality/%s/department/%s/section/%s/parcel' % (gid, aid, sid) h = self.base_headers p = { 'data': 'adp' } res = capakey_rest_gateway_request(url, h, p).json() return [ Perceel( r['perceelnummer'], sectie, r['capakey'], self.parse_percid(r['capakey']), ) for r in res['parcels'] ] if self.caches['short'].is_configured: key = 'list_percelen_by_sectie_rest percelen = self.caches['short'].get_or_create(key, creator) else: percelen = creator() for p in percelen: p.set_gateway(self) return percelen
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_urls'}, {'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'}, {'id': '7', 'type': 'string', 'children': [], 'value': '"total_clicks desc"'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '26']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'req_data'}; {'id': '18', 'type': 'list', 'children': ['19', '20', '21'], 'value': '[ None, order, fmt_paging(offset, count) ]'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'fmt_paging'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '26', 'type': 'return_statement', 'children': ['27']}, {'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': 'request'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': '"query:Message_Url"'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'req_data'}
def get_urls(self, order="total_clicks desc", offset=None, count=None): req_data = [ None, order, fmt_paging(offset, count) ] return self.request("query:Message_Url", req_data)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_message_urls'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'message_id'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '8', 'type': 'string', 'children': [], 'value': '"total_clicks desc"'}, {'id': '9', 'type': 'block', 'children': ['10', '23']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'req_data'}, {'id': '13', 'type': 'list', 'children': ['14', '21', '22'], 'value': '[ { "message_id": str(message_id) }, order, None ]'}; {'id': '14', 'type': 'dictionary', 'children': ['15']}, {'id': '15', 'type': 'pair', 'children': ['16', '17']}; {'id': '16', 'type': 'string', 'children': [], 'value': '"message_id"'}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'message_id'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'return_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30']}, {'id': '29', 'type': 'string', 'children': [], 'value': '"query:Message_Url"'}
def get_message_urls(self, message_id, order="total_clicks desc"): req_data = [ { "message_id": str(message_id) }, order, None ] return self.request("query:Message_Url", req_data)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '29']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'trade_history'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'from_'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'from_id'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'end_id'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'since'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '28', 'type': 'None', 'children': []}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'return_statement', 'children': ['31']}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': '_trade_api_call'}, {'id': '35', 'type': 'argument_list', 'children': ['36', '37', '40', '43', '46', '49', '52', '55', '58']}; {'id': '36', 'type': 'string', 'children': [], 'value': "'TradeHistory'"}, {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'from_'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'from_'}; {'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'from_id'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'from_id'}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'end_id'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'end_id'}, {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'since'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'since'}, {'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'pair'}
def trade_history( self, from_=None, count=None, from_id=None, end_id=None, order=None, since=None, end=None, pair=None ): return self._trade_api_call( 'TradeHistory', from_=from_, count=count, from_id=from_id, end_id=end_id, order=order, since=since, end=end, pair=pair )
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'trans_history'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'from_'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'from_id'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'end_id'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'since'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'return_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': '_trade_api_call'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34', '37', '40', '43', '46', '49', '52']}, {'id': '33', 'type': 'string', 'children': [], 'value': "'TransHistory'"}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'from_'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'from_'}, {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'from_id'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'from_id'}, {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'end_id'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'end_id'}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'since'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'since'}; {'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'end'}
def trans_history( self, from_=None, count=None, from_id=None, end_id=None, order=None, since=None, end=None ): return self._trade_api_call( 'TransHistory', from_=from_, count=count, from_id=from_id, end_id=end_id, order=order, since=since, end=end )
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_atom_type_symbol'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'calc'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '8', 'type': 'block', 'children': ['9', '17', '25', '36']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '12', 'type': 'attribute', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'calc'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'dictionary'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'parameters'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'get_dict'}; {'id': '24', 'type': 'argument_list', 'children': []}, {'id': '25', 'type': 'if_statement', 'children': ['26', '33']}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': 'not'}, {'id': '27', 'type': 'string', 'children': [], 'value': "'basis_set'"}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'dictionary'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '32', 'type': 'argument_list', 'children': []}, {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'return_statement', 'children': ['35']}, {'id': '35', 'type': 'None', 'children': []}; {'id': '36', 'type': 'return_statement', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '46']}, {'id': '41', 'type': 'attribute', 'children': ['42', '45']}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'dictionary'}; {'id': '44', 'type': 'string', 'children': [], 'value': "'basis_set'"}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'keys'}
def get_atom_type_symbol(cls,calc,**kwargs): parameters = calc.out.output dictionary = parameters.get_dict() if 'basis_set' not in dictionary.keys(): return None return sorted(dictionary['basis_set'].keys())
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_url'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '19']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '9', 'type': 'boolean_operator', 'children': ['10', '18'], 'value': 'or'}; {'id': '10', 'type': 'boolean_operator', 'children': ['11', '17'], 'value': 'and'}, {'id': '11', 'type': 'parenthesized_expression', 'children': ['12'], 'value': '()'}; {'id': '12', 'type': 'comparison_operator', 'children': ['13', '16'], 'value': '=='}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'sort_direction'}; {'id': '16', 'type': 'string', 'children': [], 'value': '"asc"'}, {'id': '17', 'type': 'string', 'children': [], 'value': '"-"'}; {'id': '18', 'type': 'string', 'children': [], 'value': '""'}, {'id': '19', 'type': 'return_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': 'table'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'get_url'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'order_by'}, {'id': '29', 'type': 'binary_operator', 'children': ['30', '31'], 'value': '+'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'name'}
def sort_url(self): prefix = (self.sort_direction == "asc") and "-" or "" return self.table.get_url(order_by=prefix + self.name)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'append'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'newconfig'}; {'id': '6', 'type': 'block', 'children': ['7', '52', '102', '115', '136']}, {'id': '7', 'type': 'for_statement', 'children': ['8', '9', '21']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'attr_name'}, {'id': '9', 'type': 'tuple', 'children': ['10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20']}; {'id': '10', 'type': 'string', 'children': [], 'value': "'title'"}, {'id': '11', 'type': 'string', 'children': [], 'value': "'body'"}; {'id': '12', 'type': 'string', 'children': [], 'value': "'author'"}, {'id': '13', 'type': 'string', 'children': [], 'value': "'date'"}; {'id': '14', 'type': 'string', 'children': [], 'value': "'strip'"}, {'id': '15', 'type': 'string', 'children': [], 'value': "'strip_id_or_class'"}; {'id': '16', 'type': 'string', 'children': [], 'value': "'strip_image_src'"}, {'id': '17', 'type': 'string', 'children': [], 'value': "'single_page_link'"}; {'id': '18', 'type': 'string', 'children': [], 'value': "'single_page_link_in_feed'"}, {'id': '19', 'type': 'string', 'children': [], 'value': "'next_page_link'"}; {'id': '20', 'type': 'string', 'children': [], 'value': "'http_header'"}, {'id': '21', 'type': 'block', 'children': ['22', '30', '45']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'current_set'}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'attr_name'}; {'id': '30', 'type': 'for_statement', 'children': ['31', '32', '37']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'newconfig'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'attr_name'}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'current_set'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'setattr'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '50', '51']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'attr_name'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'current_set'}; {'id': '52', 'type': 'for_statement', 'children': ['53', '54', '59']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'attr_name'}; {'id': '54', 'type': 'tuple', 'children': ['55', '56', '57', '58']}, {'id': '55', 'type': 'string', 'children': [], 'value': "'parser'"}; {'id': '56', 'type': 'string', 'children': [], 'value': "'tidy'"}, {'id': '57', 'type': 'string', 'children': [], 'value': "'prune'"}; {'id': '58', 'type': 'string', 'children': [], 'value': "'autodetect_on_failure'"}, {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'if_statement', 'children': ['61', '68']}, {'id': '61', 'type': 'comparison_operator', 'children': ['62', '67'], 'value': 'is'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'attr_name'}, {'id': '67', 'type': 'None', 'children': []}; {'id': '68', 'type': 'block', 'children': ['69']}, {'id': '69', 'type': 'if_statement', 'children': ['70', '77', '89']}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '76'], 'value': 'is'}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '73', 'type': 'argument_list', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'newconfig'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'attr_name'}; {'id': '76', 'type': 'None', 'children': []}, {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'setattr'}, {'id': '81', 'type': 'argument_list', 'children': ['82', '83', '84']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'attr_name'}; {'id': '84', 'type': 'subscript', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'attr_name'}, {'id': '89', 'type': 'else_clause', 'children': ['90']}; {'id': '90', 'type': 'block', 'children': ['91']}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'setattr'}; {'id': '94', 'type': 'argument_list', 'children': ['95', '96', '97']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'attr_name'}, {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '99', 'type': 'argument_list', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'newconfig'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'attr_name'}; {'id': '102', 'type': 'if_statement', 'children': ['103', '108']}, {'id': '103', 'type': 'comparison_operator', 'children': ['104', '107'], 'value': '=='}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'parser'}, {'id': '107', 'type': 'string', 'children': [], 'value': "'libxml'"}; {'id': '108', 'type': 'block', 'children': ['109']}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '114']}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '114', 'type': 'string', 'children': [], 'value': "'lxml'"}, {'id': '115', 'type': 'for_statement', 'children': ['116', '117', '120']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'attr_name'}, {'id': '117', 'type': 'tuple', 'children': ['118', '119']}; {'id': '118', 'type': 'string', 'children': [], 'value': "'find_string'"}, {'id': '119', 'type': 'string', 'children': [], 'value': "'replace_string'"}; {'id': '120', 'type': 'block', 'children': ['121']}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '130']}, {'id': '123', 'type': 'attribute', 'children': ['124', '129']}; {'id': '124', 'type': 'call', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '126', 'type': 'argument_list', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'attr_name'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '133', 'type': 'argument_list', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'newconfig'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'attr_name'}; {'id': '136', 'type': 'if_statement', 'children': ['137', '140', '155']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'find_string'}; {'id': '140', 'type': 'block', 'children': ['141']}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'replace_patterns'}; {'id': '146', 'type': 'call', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '148', 'type': 'argument_list', 'children': ['149', '152']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'find_string'}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'replace_string'}, {'id': '155', 'type': 'else_clause', 'children': ['156']}; {'id': '156', 'type': 'block', 'children': ['157']}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '162']}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'replace_patterns'}
def append(self, newconfig): for attr_name in ( 'title', 'body', 'author', 'date', 'strip', 'strip_id_or_class', 'strip_image_src', 'single_page_link', 'single_page_link_in_feed', 'next_page_link', 'http_header' ): current_set = getattr(self, attr_name) for val in getattr(newconfig, attr_name): current_set.add(val) setattr(self, attr_name, current_set) for attr_name in ( 'parser', 'tidy', 'prune', 'autodetect_on_failure' ): if getattr(self, attr_name) is None: if getattr(newconfig, attr_name) is None: setattr(self, attr_name, self.defaults[attr_name]) else: setattr(self, attr_name, getattr(newconfig, attr_name)) if self.parser == 'libxml': self.parser = 'lxml' for attr_name in ('find_string', 'replace_string', ): getattr(self, attr_name).extend(getattr(newconfig, attr_name)) if self.find_string: self.replace_patterns = zip( self.find_string, self.replace_string) else: self.replace_patterns = None
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '__exportUsers'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '9', 'type': 'block', 'children': ['10', '14', '23', '34', '38', '81']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'position'}, {'id': '13', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'dataUsers'}, {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'getSortedUsers'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '23', 'type': 'if_statement', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'dataUsers'}, {'id': '29', 'type': 'subscript', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'dataUsers'}, {'id': '31', 'type': 'slice', 'children': ['32', '33']}; {'id': '32', 'type': 'colon', 'children': []}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'exportedUsers'}, {'id': '37', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '38', 'type': 'for_statement', 'children': ['39', '40', '41']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'dataUsers'}, {'id': '41', 'type': 'block', 'children': ['42', '50', '56', '63', '77']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'userExported'}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'export'}, {'id': '49', 'type': 'argument_list', 'children': []}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '55']}; {'id': '52', 'type': 'subscript', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'userExported'}; {'id': '54', 'type': 'string', 'children': [], 'value': '"position"'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'position'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'exportedUsers'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'userExported'}, {'id': '63', 'type': 'if_statement', 'children': ['64', '70']}; {'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': '<'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'position'}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'dataUsers'}; {'id': '70', 'type': 'block', 'children': ['71']}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '76']}, {'id': '73', 'type': 'subscript', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'userExported'}, {'id': '75', 'type': 'string', 'children': [], 'value': '"comma"'}; {'id': '76', 'type': 'True', 'children': []}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'augmented_assignment', 'children': ['79', '80'], 'value': '+='}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'position'}; {'id': '80', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '81', 'type': 'return_statement', 'children': ['82']}
def __exportUsers(self, sort, limit=0): position = 1 dataUsers = self.getSortedUsers(sort) if limit: dataUsers = dataUsers[:limit] exportedUsers = [] for u in dataUsers: userExported = u.export() userExported["position"] = position exportedUsers.append(userExported) if position < len(dataUsers): userExported["comma"] = True position += 1 return exportedUsers
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'zset_example'}, {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '10', '15', '21', '27', '40', '62', '71', '78', '85', '92', '101', '106', '113']}, {'id': '5', 'type': 'import_from_statement', 'children': ['6', '8']}; {'id': '6', 'type': 'dotted_name', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '8', 'type': 'dotted_name', 'children': ['9']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'uuid4'}; {'id': '10', 'type': 'import_from_statement', 'children': ['11', '13']}, {'id': '11', 'type': 'dotted_name', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'redis'}, {'id': '13', 'type': 'dotted_name', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'StrictRedis'}, {'id': '15', 'type': 'import_from_statement', 'children': ['16', '19']}; {'id': '16', 'type': 'dotted_name', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'zato'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'redis_paginator'}, {'id': '19', 'type': 'dotted_name', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'ZSetPaginator'}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'conn'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'StrictRedis'}; {'id': '26', 'type': 'argument_list', 'children': []}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': "'paginator:{}'"}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'attribute', 'children': ['36', '39']}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'uuid4'}; {'id': '38', 'type': 'argument_list', 'children': []}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'hex'}; {'id': '40', 'type': 'for_statement', 'children': ['41', '42', '47']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}, {'id': '45', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '46', 'type': 'integer', 'children': [], 'value': '18'}, {'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': 'conn'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'zadd'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '55', '56']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'chr'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'binary_operator', 'children': ['60', '61'], 'value': '+'}; {'id': '60', 'type': 'integer', 'children': [], 'value': '96'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'ZSetPaginator'}, {'id': '67', 'type': 'argument_list', 'children': ['68', '69', '70']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'conn'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '70', 'type': 'integer', 'children': [], 'value': '6'}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'num_pages'}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'page_range'}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'page'}, {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'page'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'object_list'}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'conn'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'delete'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'key'}
def zset_example(): from uuid import uuid4 from redis import StrictRedis from zato.redis_paginator import ZSetPaginator conn = StrictRedis() key = 'paginator:{}'.format(uuid4().hex) for x in range(1, 18): conn.zadd(key, x, chr(96 + x)) p = ZSetPaginator(conn, key, 6) print(p.count) print(p.num_pages) print(p.page_range) page = p.page(3) print(page) print(page.object_list) conn.delete(key)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'paths_by_depth'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'paths'}, {'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', '26']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'paths'}, {'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': 'path'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'attribute', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'sep'}; {'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'reverse'}
def paths_by_depth(paths): return sorted( paths, key=lambda path: path.count(os.path.sep), reverse=True )
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'normalize_date'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'date'}, {'id': '5', 'type': 'block', 'children': ['6', '8', '117']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'string', 'children': [], 'value': '\'\'\'normalize the specified date to milliseconds since the epoch\n If it is a string, it is assumed to be some sort of datetime such as\n "2015-12-27" or "2015-12-27T11:01:20.954". If date is a naive datetime,\n it is assumed to be UTC.\n If numeric arguments are beyond 5138-11-16 (100,000,000,000 seconds\n after epoch), they are interpreted as milliseconds since the epoch.\n \'\'\''}; {'id': '8', 'type': 'if_statement', 'children': ['9', '14', '16', '32', '101']}, {'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': 'date'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'pass_statement', 'children': []}; {'id': '16', 'type': 'elif_clause', 'children': ['17', '20']}, {'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': '=='}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'date'}, {'id': '19', 'type': 'string', 'children': [], 'value': '"now"'}; {'id': '20', 'type': 'block', 'children': ['21']}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'pytz'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'UTC'}; {'id': '32', 'type': 'elif_clause', 'children': ['33', '42']}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '35', 'type': 'argument_list', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'date'}, {'id': '37', 'type': 'tuple', 'children': ['38', '39', '40', '41']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'basestring'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'long'}; {'id': '42', 'type': 'block', 'children': ['43']}, {'id': '43', 'type': 'try_statement', 'children': ['44', '75']}; {'id': '44', 'type': 'block', 'children': ['45', '52', '63']}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'ts'}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '52', 'type': 'if_statement', 'children': ['53', '56']}, {'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': '>'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'ts'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'MAX_TS_SECONDS'}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'ts'}; {'id': '60', 'type': 'binary_operator', 'children': ['61', '62'], 'value': '/'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'ts'}; {'id': '62', 'type': 'float', 'children': [], 'value': '1000.0'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '66', 'type': 'call', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'utcfromtimestamp'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'ts'}, {'id': '75', 'type': 'except_clause', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'try_statement', 'children': ['79', '87']}, {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'date'}, {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'dateparse'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'date'}, {'id': '87', 'type': 'except_clause', 'children': ['88', '92']}; {'id': '88', 'type': 'as_pattern', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '90', 'type': 'as_pattern_target', 'children': ['91']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '92', 'type': 'block', 'children': ['93']}, {'id': '93', 'type': 'raise_statement', 'children': ['94']}; {'id': '94', 'type': 'call', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'InvalidDatalakeMetadata'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '101', 'type': 'else_clause', 'children': ['102']}; {'id': '102', 'type': 'block', 'children': ['103', '112']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '106', 'type': 'call', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'string', 'children': [], 'value': "'could not parse a date from {!r}'"}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '112', 'type': 'raise_statement', 'children': ['113']}, {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'InvalidDatalakeMetadata'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '117', 'type': 'return_statement', 'children': ['118']}; {'id': '118', 'type': 'call', 'children': ['119', '122']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'Metadata'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': '_from_datetime'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'date'}
def normalize_date(date): '''normalize the specified date to milliseconds since the epoch If it is a string, it is assumed to be some sort of datetime such as "2015-12-27" or "2015-12-27T11:01:20.954". If date is a naive datetime, it is assumed to be UTC. If numeric arguments are beyond 5138-11-16 (100,000,000,000 seconds after epoch), they are interpreted as milliseconds since the epoch. ''' if isinstance(date, datetime): pass elif date == "now": date = datetime.now(pytz.UTC) elif isinstance(date, (basestring, int, float, long)): try: ts = float(date) if ts > MAX_TS_SECONDS: ts = ts / 1000.0 date = datetime.utcfromtimestamp(float(ts)) except ValueError: try: date = dateparse(date) except ValueError as e: raise InvalidDatalakeMetadata(str(e)) else: msg = 'could not parse a date from {!r}'.format(date) raise InvalidDatalakeMetadata(msg) return Metadata._from_datetime(date)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'format_float'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'max_width'}; {'id': '6', 'type': 'block', 'children': ['7', '9', '28', '37', '46']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'string', 'children': [], 'value': "'''format_float will ensure that a number's decimal part is truncated to\n fit within some bounds, unless the whole part is wider than max_width,\n which is a problem you need to sort out yourself.\n '''"}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'whole_width'}; {'id': '12', 'type': 'binary_operator', 'children': ['13', '27'], 'value': '+'}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'math'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'log10'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'binary_operator', 'children': ['22', '26'], 'value': '+'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '26', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '27', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'sign_width'}, {'id': '31', 'type': 'conditional_expression', 'children': ['32', '33', '36'], 'value': 'if'}; {'id': '32', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': '<'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '36', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'decimal_point_width'}; {'id': '40', 'type': 'conditional_expression', 'children': ['41', '42', '45'], 'value': 'if'}, {'id': '41', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': '>='}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'max_width'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'whole_width'}, {'id': '45', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '46', 'type': 'return_statement', 'children': ['47']}, {'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '%'}; {'id': '48', 'type': 'string', 'children': [], 'value': "'%.*f'"}, {'id': '49', 'type': 'tuple', 'children': ['50', '57']}; {'id': '50', 'type': 'binary_operator', 'children': ['51', '56'], 'value': '-'}, {'id': '51', 'type': 'binary_operator', 'children': ['52', '55'], 'value': '-'}; {'id': '52', 'type': 'binary_operator', 'children': ['53', '54'], 'value': '-'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'max_width'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'whole_width'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'sign_width'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'decimal_point_width'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'x'}
def format_float(x, max_width): '''format_float will ensure that a number's decimal part is truncated to fit within some bounds, unless the whole part is wider than max_width, which is a problem you need to sort out yourself. ''' whole_width = int(math.log10(abs(x) + 1)) + 1 sign_width = 1 if x < 0 else 0 decimal_point_width = 1 if max_width >= whole_width else 0 return '%.*f' % (max_width - whole_width - sign_width - decimal_point_width, x)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '__cleanup'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '14', '53', '75', '82', '90', '97']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', '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': '_run'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'if_statement', 'children': ['15', '38', '46']}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'check_process_termination'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '23', '30', '33']}; {'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'proc'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '_proc'}, {'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'timeout'}, {'id': '25', 'type': 'binary_operator', 'children': ['26', '27'], 'value': '*'}; {'id': '26', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'interval'}; {'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '32', 'type': 'string', 'children': [], 'value': "''"}, {'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'auto_kill_on_last_resort'}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': '_auto_kill_on_last_resort'}; {'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': 'log'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'string', 'children': [], 'value': '"cleanup successful"'}; {'id': '46', 'type': 'else_clause', 'children': ['47']}, {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'raise_statement', 'children': ['49']}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'string', 'children': [], 'value': '"cleanup FAILED!"'}, {'id': '53', 'type': 'try_statement', 'children': ['54', '71']}; {'id': '54', 'type': 'block', 'children': ['55', '63']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '62']}, {'id': '57', 'type': 'attribute', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'conn_send'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '62', 'type': 'argument_list', 'children': []}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '70']}, {'id': '65', 'type': 'attribute', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': '_log_queue_listener'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '70', 'type': 'argument_list', 'children': []}, {'id': '71', 'type': 'except_clause', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'OSError'}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'pass_statement', 'children': []}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'string', 'children': [], 'value': '"wait for monitor thread to join"'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'call', 'children': ['84', '89']}; {'id': '84', 'type': 'attribute', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': '_monitor_thread'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '89', 'type': 'argument_list', 'children': []}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'string', 'children': [], 'value': '"monitor thread to joined"'}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '104']}, {'id': '99', 'type': 'attribute', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': '_func_running'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'value'}
def __cleanup(self): self._run.value = False if check_process_termination(proc = self._proc, timeout = 2*self.interval, prefix = '', auto_kill_on_last_resort = self._auto_kill_on_last_resort): log.debug("cleanup successful") else: raise RuntimeError("cleanup FAILED!") try: self.conn_send.close() self._log_queue_listener.stop() except OSError: pass log.debug("wait for monitor thread to join") self._monitor_thread.join() log.debug("monitor thread to joined") self._func_running.value = False
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'regroup'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'target'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'expression'}; {'id': '6', 'type': 'block', 'children': ['7', '13']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '10']}; {'id': '8', 'type': 'not_operator', 'children': ['9']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '10', 'type': 'block', 'children': ['11']}, {'id': '11', 'type': 'return_statement', 'children': ['12']}; {'id': '12', 'type': 'string', 'children': [], 'value': "''"}, {'id': '13', 'type': 'return_statement', 'children': ['14']}; {'id': '14', 'type': 'list_comprehension', 'children': ['15', '25']}, {'id': '15', 'type': 'dictionary', 'children': ['16', '19']}; {'id': '16', 'type': 'pair', 'children': ['17', '18']}, {'id': '17', 'type': 'string', 'children': [], 'value': "'grouper'"}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '19', 'type': 'pair', 'children': ['20', '21']}; {'id': '20', 'type': 'string', 'children': [], 'value': "'list'"}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '25', 'type': 'for_in_clause', 'children': ['26', '29']}; {'id': '26', 'type': 'pattern_list', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'groupby'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'obj_list'}, {'id': '33', 'type': 'lambda', 'children': ['34', '41']}; {'id': '34', 'type': 'lambda_parameters', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '36', 'type': 'default_parameter', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'expression'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'resolve'}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '43', 'type': 'argument_list', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '45', 'type': 'True', 'children': []}
def regroup(target, expression): if not target: return '' return [ {'grouper': key, 'list': list(val)} for key, val in groupby(obj_list, lambda v, f=expression.resolve: f(v, True)) ]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'entityTriples'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'rdfGraph'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'anEntity'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'excludeProps'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'excludeBNodes'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'orderProps'}; {'id': '14', 'type': 'list', 'children': ['15', '16', '17', '20'], 'value': '[RDF, RDFS, OWL.OWLNS, DC.DCNS]'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'RDF'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'RDFS'}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'OWL'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'OWLNS'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'DC'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'DCNS'}, {'id': '23', 'type': 'block', 'children': ['24', '28', '36', '72', '166']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'temp'}, {'id': '27', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '28', 'type': 'if_statement', 'children': ['29', '31']}, {'id': '29', 'type': 'not_operator', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'excludeProps'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'excludeProps'}, {'id': '35', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '36', 'type': 'for_statement', 'children': ['37', '41', '50']}, {'id': '37', 'type': 'pattern_list', 'children': ['38', '39', '40']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'z'}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'rdfGraph'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'triples'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'tuple', 'children': ['47', '48', '49']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'anEntity'}; {'id': '48', 'type': 'None', 'children': []}, {'id': '49', 'type': 'None', 'children': []}; {'id': '50', 'type': 'block', 'children': ['51', '60']}, {'id': '51', 'type': 'if_statement', 'children': ['52', '58']}; {'id': '52', 'type': 'boolean_operator', 'children': ['53', '54'], 'value': 'and'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'excludeBNodes'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'isBlankNode'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'z'}; {'id': '58', 'type': 'block', 'children': ['59']}, {'id': '59', 'type': 'continue_statement', 'children': []}; {'id': '60', 'type': 'if_statement', 'children': ['61', '64']}, {'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'not'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'excludeProps'}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'augmented_assignment', 'children': ['67', '68'], 'value': '+='}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '68', 'type': 'list', 'children': ['69'], 'value': '[(y, z)]'}, {'id': '69', 'type': 'tuple', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'z'}; {'id': '72', 'type': 'if_statement', 'children': ['73', '82', '148']}, {'id': '73', 'type': 'comparison_operator', 'children': ['74', '78'], 'value': '=='}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'orderProps'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '82', 'type': 'block', 'children': ['83', '97', '114', '128']}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'orderedUris'}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'sortByNamespacePrefix'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '96']}, {'id': '89', 'type': 'list_comprehension', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '91', 'type': 'for_in_clause', 'children': ['92', '95']}; {'id': '92', 'type': 'pattern_list', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'z'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'orderProps'}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'orderedUris'}; {'id': '100', 'type': 'list_comprehension', 'children': ['101', '106']}, {'id': '101', 'type': 'tuple', 'children': ['102', '105']}; {'id': '102', 'type': 'binary_operator', 'children': ['103', '104'], 'value': '+'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '104', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '106', 'type': 'for_in_clause', 'children': ['107', '110']}, {'id': '107', 'type': 'pattern_list', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'orderedUris'}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'rank'}, {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '119', 'type': 'generator_expression', 'children': ['120', '123']}; {'id': '120', 'type': 'tuple', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'rank'}, {'id': '123', 'type': 'for_in_clause', 'children': ['124', '127']}; {'id': '124', 'type': 'tuple_pattern', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'rank'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'orderedUris'}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'temp'}, {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '133', 'type': 'argument_list', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'temp'}, {'id': '135', 'type': 'keyword_argument', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '137', 'type': 'lambda', 'children': ['138', '140']}; {'id': '138', 'type': 'lambda_parameters', 'children': ['139']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'tup'}; {'id': '140', 'type': 'call', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'rank'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'tup'}, {'id': '147', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '148', 'type': 'elif_clause', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'orderProps'}; {'id': '150', 'type': 'block', 'children': ['151']}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '154', 'type': 'call', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '156', 'type': 'argument_list', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '160', 'type': 'lambda', 'children': ['161', '163']}, {'id': '161', 'type': 'lambda_parameters', 'children': ['162']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'tup'}, {'id': '163', 'type': 'subscript', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'tup'}, {'id': '165', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '166', 'type': 'return_statement', 'children': ['167']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'temp'}
def entityTriples(rdfGraph, anEntity, excludeProps=False, excludeBNodes=False, orderProps=[RDF, RDFS, OWL.OWLNS, DC.DCNS]): temp = [] if not excludeProps: excludeProps = [] for x, y, z in rdfGraph.triples((anEntity, None, None)): if excludeBNodes and isBlankNode(z): continue if y not in excludeProps: temp += [(y, z)] if type(orderProps) == type([]): orderedUris = sortByNamespacePrefix([y for y, z in temp], orderProps) orderedUris = [(n + 1, x) for n, x in enumerate(orderedUris)] rank = dict((key, rank) for (rank, key) in orderedUris) temp = sorted(temp, key=lambda tup: rank.get(tup[0])) elif orderProps: temp = sorted(temp, key=lambda tup: tup[0]) return temp
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'msvd'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '5', 'type': 'block', 'children': ['6', '20', '28', '34', '42', '48']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '12']}; {'id': '8', 'type': 'pattern_list', 'children': ['9', '10', '11']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'vdgr'}; {'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': 'np'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'linalg'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'svd'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'argsort'}, {'id': '27', 'type': 'argument_list', 'children': []}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '31', 'type': 'subscript', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'u'}, {'id': '37', 'type': 'subscript', 'children': ['38', '39', '41']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'u'}, {'id': '39', 'type': 'slice', 'children': ['40']}; {'id': '40', 'type': 'colon', 'children': []}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'vdgr'}, {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'vdgr'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '48', 'type': 'return_statement', 'children': ['49']}, {'id': '49', 'type': 'expression_list', 'children': ['50', '51', '52']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'u'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '52', 'type': 'attribute', 'children': ['53', '58']}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'vdgr'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'conj'}, {'id': '57', 'type': 'argument_list', 'children': []}
def msvd(m): u, s, vdgr = np.linalg.svd(m) order = s.argsort() s = s[order] u= u[:,order] vdgr = vdgr[order] return u, s, vdgr.conj().T
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_rows_sort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '6', 'type': 'block', 'children': ['7']}, {'id': '7', 'type': 'return_statement', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '10', 'type': 'argument_list', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '12', 'type': 'keyword_argument', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '14', 'type': 'lambda', 'children': ['15', '17']}, {'id': '15', 'type': 'lambda_parameters', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '17', 'type': 'tuple', 'children': ['18', '23']}; {'id': '18', 'type': 'subscript', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '_key_start_date'}, {'id': '23', 'type': 'subscript', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': '_key_end_date'}
def _rows_sort(self, rows): return sorted(rows, key=lambda row: (row[self._key_start_date], row[self._key_end_date]))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_rows'}, {'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': 'sort'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '13', '51']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '12', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '13', 'type': 'for_statement', 'children': ['14', '17', '36']}; {'id': '14', 'type': 'pattern_list', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'rows'}, {'id': '17', 'type': 'conditional_expression', 'children': ['18', '28', '29'], 'value': 'if'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'call', 'children': ['22', '27']}; {'id': '22', 'type': 'attribute', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': '_rows'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '27', 'type': 'argument_list', 'children': []}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'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': '_rows'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'block', 'children': ['37', '44']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': '_rows_int2date'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'rows'}, {'id': '51', 'type': 'return_statement', 'children': ['52']}
def get_rows(self, sort=False): ret = [] for _, rows in sorted(self._rows.items()) if sort else self._rows.items(): self._rows_int2date(rows) ret.extend(rows) return ret
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_entries'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '5', 'type': 'block', 'children': ['6', '14', '57', '63', '69']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '11']}; {'id': '8', 'type': 'pattern_list', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'dirs'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'files'}, {'id': '11', 'type': 'expression_list', 'children': ['12', '13']}; {'id': '12', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '13', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '14', 'type': 'for_statement', 'children': ['15', '16', '22']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'listdir'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'if_statement', 'children': ['24', '40', '48']}; {'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': 'os'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'call', 'children': ['32', '37']}; {'id': '32', 'type': 'attribute', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '37', 'type': 'argument_list', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'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': 'dirs'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'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': 'files'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'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': 'dirs'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '62', 'type': 'argument_list', 'children': []}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'files'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '68', 'type': 'argument_list', 'children': []}, {'id': '69', 'type': 'return_statement', 'children': ['70']}; {'id': '70', 'type': 'expression_list', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'dirs'}
def get_entries(path): dirs, files = [], [] for entry in os.listdir(path): if os.path.isdir(os.path.join(path, entry)): dirs.append(entry) else: files.append(entry) dirs.sort() files.sort() return dirs, files
{'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': 'ctx'}, {'id': '5', 'type': 'block', 'children': ['6', '14', '22', '30', '38', '49']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'head'}, {'id': '9', 'type': 'attribute', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'ctx'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'head'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'vcf_handle'}, {'id': '17', 'type': 'attribute', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'ctx'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'handle'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'outfile'}, {'id': '25', 'type': 'attribute', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'ctx'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'silent'}, {'id': '33', 'type': 'attribute', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'ctx'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'silent'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'print_headers'}, {'id': '41', 'type': 'argument_list', 'children': ['42', '43', '46']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'head'}, {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'outfile'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'silent'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'silent'}, {'id': '49', 'type': 'for_statement', 'children': ['50', '51', '55']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'sort_variants'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'vcf_handle'}, {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'print_variant'}, {'id': '59', 'type': 'argument_list', 'children': ['60', '63', '66']}; {'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'variant_line'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'outfile'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'silent'}
def sort(ctx): head = ctx.parent.head vcf_handle = ctx.parent.handle outfile = ctx.parent.outfile silent = ctx.parent.silent print_headers(head, outfile=outfile, silent=silent) for line in sort_variants(vcf_handle): print_variant(variant_line=line, outfile=outfile, silent=silent)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort_to_str'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '14', '53', '67']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'params_list'}, {'id': '9', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'timestamp'}, {'id': '13', 'type': 'string', 'children': [], 'value': '""'}; {'id': '14', 'type': 'for_statement', 'children': ['15', '18', '27']}, {'id': '15', 'type': 'pattern_list', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '18', 'type': 'call', 'children': ['19', '26']}, {'id': '19', 'type': 'attribute', 'children': ['20', '25']}; {'id': '20', 'type': 'subscript', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': '_solr_params'}; {'id': '24', 'type': 'string', 'children': [], 'value': "'sort'"}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '26', 'type': 'argument_list', 'children': []}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'if_statement', 'children': ['29', '32', '47']}, {'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': '!='}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '31', 'type': 'string', 'children': [], 'value': '"timestamp"'}; {'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': 'params_list'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'string', 'children': [], 'value': '" "'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'list', 'children': ['45', '46'], 'value': '[k, v]'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '47', 'type': 'else_clause', 'children': ['48']}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'v'}, {'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': 'params_list'}, {'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': 'string', 'children': [], 'value': '" "'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'list', 'children': ['65', '66'], 'value': "['timestamp', timestamp]"}, {'id': '65', 'type': 'string', 'children': [], 'value': "'timestamp'"}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'timestamp'}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '74']}, {'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': '_solr_params'}, {'id': '73', 'type': 'string', 'children': [], 'value': "'sort'"}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'string', 'children': [], 'value': '", "'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'params_list'}
def _sort_to_str(self): params_list = [] timestamp = "" for k, v in self._solr_params['sort'].items(): if k != "timestamp": params_list.append(" ".join([k, v])) else: timestamp = v params_list.append(" ".join(['timestamp', timestamp])) self._solr_params['sort'] = ", ".join(params_list)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_video_ts_file_paths'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dvd_path'}, {'id': '5', 'type': 'block', 'children': ['6', '14', '18', '46']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'video_ts_folder_path'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '11', 'type': 'argument_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'dvd_path'}, {'id': '13', 'type': 'string', 'children': [], 'value': '"VIDEO_TS"'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'video_ts_file_paths'}, {'id': '17', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '18', 'type': 'for_statement', 'children': ['19', '20', '24']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'video_ts_folder_content_name'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'listdir'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'video_ts_folder_path'}; {'id': '24', 'type': 'block', 'children': ['25', '33']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'video_ts_folder_content_path'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'video_ts_folder_path'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'video_ts_folder_content_name'}, {'id': '33', 'type': 'if_statement', 'children': ['34', '38']}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'video_ts_folder_content_path'}; {'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': 'video_ts_file_paths'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'video_ts_folder_content_path'}; {'id': '46', 'type': 'return_statement', 'children': ['47']}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}
def _get_video_ts_file_paths(dvd_path): video_ts_folder_path = join(dvd_path, "VIDEO_TS") video_ts_file_paths = [] for video_ts_folder_content_name in listdir(video_ts_folder_path): video_ts_folder_content_path = join(video_ts_folder_path, video_ts_folder_content_name) if isfile(video_ts_folder_content_path): video_ts_file_paths.append(video_ts_folder_content_path) return sorted(video_ts_file_paths)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_ranges'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'inranges'}, {'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': 'inranges'}, {'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', '26']}, {'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'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'x'}
def sort_ranges(inranges): return sorted(inranges,key=lambda x: (x.chr,x.start,x.end,x.direction))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'subtract_ranges'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'r1s'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'r2s'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'already_sorted'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '16', '34', '38', '53', '57', '61', '254']}; {'id': '10', 'type': 'import_from_statement', 'children': ['11', '14']}, {'id': '11', 'type': 'dotted_name', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'seqtools'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'stream'}; {'id': '14', 'type': 'dotted_name', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'MultiLocusStream'}; {'id': '16', 'type': 'if_statement', 'children': ['17', '19']}, {'id': '17', 'type': 'not_operator', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'already_sorted'}, {'id': '19', 'type': 'block', 'children': ['20', '27']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'r1s'}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'merge_ranges'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'r1s'}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'r2s'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'merge_ranges'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'r2s'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'outputs'}, {'id': '37', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'mls'}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'MultiLocusStream'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'list', 'children': ['45', '49'], 'value': '[BedArrayStream(r1s),BedArrayStream(r2s)]'}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'BedArrayStream'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'r1s'}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'BedArrayStream'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'r2s'}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'tot1'}; {'id': '56', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'tot2'}; {'id': '60', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '61', 'type': 'for_statement', 'children': ['62', '63', '64']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'loc'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'mls'}; {'id': '64', 'type': 'block', 'children': ['65', '71', '77', '84', '91', '100', '113', '117', '134', '138', '145', '206']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'loc'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'payload'}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '76']}, {'id': '73', 'type': 'list_pattern', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'beds1'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'beds2'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'beds1'}; {'id': '80', 'type': 'subscript', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'beds1'}; {'id': '82', 'type': 'slice', 'children': ['83']}, {'id': '83', 'type': 'colon', 'children': []}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'beds2'}, {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'beds2'}, {'id': '89', 'type': 'slice', 'children': ['90']}; {'id': '90', 'type': 'colon', 'children': []}, {'id': '91', 'type': 'if_statement', 'children': ['92', '98']}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '97'], 'value': '=='}, {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'beds1'}, {'id': '97', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '98', 'type': 'block', 'children': ['99']}, {'id': '99', 'type': 'continue_statement', 'children': []}; {'id': '100', 'type': 'if_statement', 'children': ['101', '107']}, {'id': '101', 'type': 'comparison_operator', 'children': ['102', '106'], 'value': '=='}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'beds2'}; {'id': '106', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '107', 'type': 'block', 'children': ['108', '112']}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'augmented_assignment', 'children': ['110', '111'], 'value': '+='}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'outputs'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'beds1'}; {'id': '112', 'type': 'continue_statement', 'children': []}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '116', 'type': 'dictionary', 'children': []}, {'id': '117', 'type': 'for_statement', 'children': ['118', '119', '127']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '121', 'type': 'argument_list', 'children': ['122', '123']}; {'id': '122', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '123', 'type': 'call', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'beds1'}, {'id': '127', 'type': 'block', 'children': ['128']}; {'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': 'mapping'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '133', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'beds2min'}, {'id': '137', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'beds2max'}, {'id': '141', 'type': 'call', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '143', 'type': 'argument_list', 'children': ['144']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'beds2'}, {'id': '145', 'type': 'for_statement', 'children': ['146', '147', '155']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '147', 'type': 'call', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '149', 'type': 'argument_list', 'children': ['150', '151']}; {'id': '150', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '151', 'type': 'call', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'beds1'}, {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'for_statement', 'children': ['157', '158', '163']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '158', 'type': 'call', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '160', 'type': 'argument_list', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'beds2min'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'beds2max'}, {'id': '163', 'type': 'block', 'children': ['164', '177']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'assignment', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'cmpval'}, {'id': '167', 'type': 'call', 'children': ['168', '173']}; {'id': '168', 'type': 'attribute', 'children': ['169', '172']}, {'id': '169', 'type': 'subscript', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'beds1'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'cmp'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'subscript', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'beds2'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '177', 'type': 'if_statement', 'children': ['178', '182', '189', '203']}; {'id': '178', 'type': 'comparison_operator', 'children': ['179', '180'], 'value': '=='}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'cmpval'}; {'id': '180', 'type': 'unary_operator', 'children': ['181'], 'value': '-'}, {'id': '181', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '182', 'type': 'block', 'children': ['183']}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'beds2min'}; {'id': '186', 'type': 'binary_operator', 'children': ['187', '188'], 'value': '+'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '188', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '189', 'type': 'elif_clause', 'children': ['190', '193']}; {'id': '190', 'type': 'comparison_operator', 'children': ['191', '192'], 'value': '=='}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'cmpval'}; {'id': '192', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '193', 'type': 'block', 'children': ['194']}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'call', 'children': ['196', '201']}; {'id': '196', 'type': 'attribute', 'children': ['197', '200']}, {'id': '197', 'type': 'subscript', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'mapping'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '201', 'type': 'argument_list', 'children': ['202']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '203', 'type': 'else_clause', 'children': ['204']}; {'id': '204', 'type': 'block', 'children': ['205']}, {'id': '205', 'type': 'break_statement', 'children': []}; {'id': '206', 'type': 'for_statement', 'children': ['207', '208', '216']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '208', 'type': 'call', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '210', 'type': 'argument_list', 'children': ['211', '212']}, {'id': '211', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '212', 'type': 'call', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '214', 'type': 'argument_list', 'children': ['215']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'beds1'}; {'id': '216', 'type': 'block', 'children': ['217']}, {'id': '217', 'type': 'if_statement', 'children': ['218', '226', '231']}; {'id': '218', 'type': 'comparison_operator', 'children': ['219', '225'], 'value': '=='}, {'id': '219', 'type': 'call', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'subscript', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '225', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '226', 'type': 'block', 'children': ['227']}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'augmented_assignment', 'children': ['229', '230'], 'value': '+='}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'outputs'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'beds1'}, {'id': '231', 'type': 'else_clause', 'children': ['232']}; {'id': '232', 'type': 'block', 'children': ['233']}, {'id': '233', 'type': 'expression_statement', 'children': ['234']}; {'id': '234', 'type': 'augmented_assignment', 'children': ['235', '236'], 'value': '+='}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'outputs'}; {'id': '236', 'type': 'call', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'subtract_range_array'}; {'id': '238', 'type': 'argument_list', 'children': ['239', '242', '251']}, {'id': '239', 'type': 'subscript', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'beds1'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '242', 'type': 'list_comprehension', 'children': ['243', '246']}, {'id': '243', 'type': 'subscript', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'beds2'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '246', 'type': 'for_in_clause', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '248', 'type': 'subscript', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '251', 'type': 'keyword_argument', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'is_sorted'}, {'id': '253', 'type': 'True', 'children': []}; {'id': '254', 'type': 'return_statement', 'children': ['255']}, {'id': '255', 'type': 'call', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'merge_ranges'}, {'id': '257', 'type': 'argument_list', 'children': ['258']}
def subtract_ranges(r1s,r2s,already_sorted=False): from seqtools.stream import MultiLocusStream if not already_sorted: r1s = merge_ranges(r1s) r2s = merge_ranges(r2s) outputs = [] mls = MultiLocusStream([BedArrayStream(r1s),BedArrayStream(r2s)]) tot1 = 0 tot2 = 0 for loc in mls: v = loc.payload [beds1,beds2] =v beds1 = beds1[:] beds2 = beds2[:] if len(beds1)==0: continue if len(beds2)==0: outputs += beds1 continue mapping = {} for i in range(0,len(beds1)): mapping[i] = [] beds2min = 0 beds2max = len(beds2) for i in range(0,len(beds1)): for j in range(beds2min,beds2max): cmpval = beds1[i].cmp(beds2[j]) if cmpval == -1: beds2min = j+1 elif cmpval == 0: mapping[i].append(j) else: break for i in range(0,len(beds1)): if len(mapping[i])==0: outputs += beds1 else: outputs += subtract_range_array(beds1[i],[beds2[j] for j in mapping[i]],is_sorted=True) return merge_ranges(outputs)